pheature/inmemory-toggle

Pheature flags In Memory toggle implementation library.

0.8.0 2023-12-03 12:49 UTC

This package is auto-updated.

Last update: 2024-11-03 14:48:25 UTC


README

Latest Version on Packagist Quality Score Type coverage Test Coverage Mutation testing badge Maintainability Total Downloads

Installation

Install it using composer package manager.

composer require pheature/inmemory-toggle

Usage

Check https://github.com/pheature-flags/pheature-flags/tree/1.0.x/examples for more examples.

<?php

declare(strict_types=1);

use Pheature\Core\Toggle\Read\Toggle;
use Pheature\InMemory\Toggle\InMemoryConfig;
use Pheature\InMemory\Toggle\InMemoryFeatureFactory;
use Pheature\InMemory\Toggle\InMemoryFeatureFinder;

require '../vendor/autoload.php';

$config = [
    'toggles' => [
        'feature_1' => [
            'id' => 'feature_1',
            'enabled' => false,
            'strategies' => []
        ],
    ]
];

$toggle = new Toggle(new InMemoryFeatureFinder(
    new InMemoryConfig($config['toggles']),
    new InMemoryFeatureFactory()
));

if ($toggle->isEnabled('feature_1')) {
    echo 'The feature_1 is work in progress.' . PHP_EOL;
}

if (false === $toggle->isEnabled('feature_1')) {
    echo 'The old functionality to be changed when the feature_1 is ready.' . PHP_EOL;
}

Contributing

Your contributions are always welcome! Please have a look at the contribution guidelines first.

License

We really believe in the Open Source Software, we built our carers around it, and we feel that we need to return our knowledge to the community. For this reason we release all our packages under BSD-3-Clause licence.