Ability to activate and deactivate features dynamically.
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Open a command console, enter your project directory and execute:
$ composer require halloverden/symfony-feature-flag-bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require halloverden/symfony-feature-flag-bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php
return [
// ...
HalloVerden\FeatureFlagBundle\HalloVerdenFeatureFlagBundle::class => ['all' => true],
];
<?php
namespace App\Entity\FeatureFlag;
use Doctrine\ORM\Mapping as ORM;
use HalloVerden\FeatureFlagBundle\Entity\FeatureFlag;
/**
* Class TestFeatureFlag
*
* @package App\Entity\FeatureFlag
*
* @ORM\Entity()
*/
class TestFeatureFlag extends FeatureFlag {
/* If you add additonal properties, override setFromConsole */
/**
* @inheritDoc
*/
public static function getType(): string {
return 'TEST';
}
}
bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate
bin/console feature-flag:create TEST
bin/console feature-flag:activate TEST
bin/console feature-flag:dectivate TEST
<?php
namespace App\Services;
use App\Entity\FeatureFlag\TestFeatureFlag;
use HalloVerden\FeatureFlagBundle\Services\FeatureFlagServiceInterface;
class SomeService {
private FeatureFlagServiceInterface $featureFlagService;
public function __construct(FeatureFlagServiceInterface $featureFlagService) {
$this->featureFlagService = $featureFlagService;
}
public function test(): void {
if (!$this->featureFlagService->isActive(TestFeatureFlag::class)) {
return; // or throw an exception
}
// Do the thing that requires this feature to be active.
}
}