em411/sylius-feature-flag-bundle-plugin
Manage em411/feature-flag-bundle
feature flags from the Sylius admin panel.
Tested on PHP 7.4 – 8.1 with Sylius 1.8+ on Symfony 4.4.
Feature flags become a Sylius resource: an admin can create, edit and delete
them in a grid. Each flag has a code, an enabled toggle, an optional value
and a description. A Doctrine-backed provider feeds the flags into the feature
flag chain at a high priority, so a database flag overrides a code-defined
feature (@AsFeature) of the same code.
composer require em411/sylius-feature-flag-bundle-plugin
// config/bundles.php
return [
// ...
Ajgarlag\FeatureFlagBundle\FeatureFlagBundle::class => ['all' => true],
Em411\SyliusFeatureFlagPlugin\Em411SyliusFeatureFlagPlugin::class => ['all' => true],
];
# config/routes/em411_sylius_feature_flag.yaml
em411_sylius_feature_flag_admin:
resource: "@Em411SyliusFeatureFlagPlugin/Resources/config/routing/admin.yaml"
prefix: /admin
The plugin ships the Doctrine mapping; generate and run a migration in your app:
bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate
After installing or upgrading, clear the Symfony cache so the bundle's translations and grid config are picked up:
bin/console cache:clear
If your project uses BitBagCommerce/SyliusAclPlugin (or a fork of it), open Configuration → Administrators → Roles, edit the role that should manage feature flags, and tick the Feature flag entries. Without this step the grid renders without Edit / Delete buttons because the ACL plugin filters out actions for routes the role hasn't been granted.
Open Configuration → Feature flags in the Sylius admin to manage flags.
Check a flag anywhere a FeatureCheckerInterface is available:
$featureChecker->isEnabled('my_flag'); // plain on/off flags
$featureChecker->getValue('my_flag'); // value-carrying flags
The plugin is intentionally context-unaware. To target a group, store the group identifiers in the flag's value and check membership in your application — for example, a flag whose value is a comma-separated list of Sylius customer group codes:
$allowed = $featureChecker->getValue('beta_checkout'); // "wholesale,vip" or false
$groups = false === $allowed ? [] : explode(',', $allowed);
$enabled = \in_array($customer->getGroup()->getCode(), $groups, true);
# config/packages/em411_sylius_feature_flag_plugin.yaml
em411_sylius_feature_flag_plugin:
provider_priority: 100 # priority of the DB provider in the feature flag chain
MIT.
How can I help you explore Laravel packages today?