halloverden / symfony-feature-flag-bundle
Ability to enable and disable feature flags with commands
Installs: 378
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.2
- doctrine/doctrine-bundle: ^2.5
- halloverden/symfony-entity-utils-bundle: ^4.3
- symfony/dependency-injection: ^6.4|^7.1
- symfony/http-kernel: ^6.4|^7.1
Requires (Dev)
- rector/rector: ^1.2
README
Ability to activate and deactivate features dynamically.
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
$ composer require halloverden/symfony-feature-flag-bundle
Applications that don't use Symfony Flex
Step 1: Download the 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
Step 2: Enable the 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], ];
Usage
Create an entity representing your feature.
<?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'; } }
Create and run migration for your new FeatureFlag
bin/console doctrine:migrations:diff bin/console doctrine:migrations:migrate
Create the FeatureFlag
bin/console feature-flag:create TEST
Activate feature
bin/console feature-flag:activate TEST
Deactivate feature
bin/console feature-flag:dectivate TEST
Check if feature is activated:
<?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. } }