A Symfony3 Bundle for opensoft/rollout
Add the bundle via composer
composer require opensoft/rollout-bundle
And activate it inside your app\AppKernel.php
newOpensoft\RolloutBundle\OpensoftRolloutBundle(),Add the following to your configuration (supports auto-wiring)
opensoft_rollout:
user_provider_service: [YOUR USER PROVIDER SERVICE]storage_service: [YOUR STORAGE SERVICE FOR ROLLOUT]user_provider_service: Add the service id (generally the FQDN with auto-wiring) of the UserProvider to which you added the RolloutUserProviderInterfacestorage_service: Defaults toOpensoft\Rollout\Storage\ArrayStorage, but you can also use the includedOpensoft\RolloutBundle\Storage\Doctrine\DoctrineORMStorageor create your own (see below for implementation)
Any rollout user must implement the RolloutUserInterface. Often, this will be your main user object in the application.
<?phpuse Opensoft/Rollout/RolloutUserInterface;
class User implements RolloutUserInterface
{
/** * @return string */publicfunctiongetRolloutIdentifier()
{
return$this->email;
}
}Expose individual users to the rollout interface by implementing the UserProviderInterface
<?phpuseDoctrine\ORM\EntityRepository;
useOpensoft\RolloutBundle\Rollout\UserProviderInterface;
class UserRepository extends EntityRepository implements UserProviderInterface
{
/** * @param mixed $id * @return RolloutUserInterface|null */publicfunctionfindByRolloutIdentifier($id)
{
return$this->findOneBy(array('email' => $id));
}
}Provide different groups of users to your rollout.
Tag all of your group definitions with the DIC tag rollout.group to expose them to the rollout interface
<?phpuseOpensoft\RolloutBundle\Rollout\GroupDefinitionInterface;
class AcmeEmployeeGroupDefinition implements GroupDefinitionInterface
{
/** * @return string */publicfunctiongetName()
{
return'acme_employee';
}
/** * @return string */publicfunctiongetDescription()
{
return'This group contains acme company employees';
}
/** * @return \Closure */publicfunctiongetCallback()
{
returnfunction(RolloutUserInterface$user) {
// Is this user an employee of acme?returnstrpos($user->getEmail(), 'acme.com') !== false;
};
}
}Implement a custom storage solution.
Note: The rollout StorageInterfacechanged in version 2.0.0.
<?phpuseOpensoft\Rollout\Storage\StorageInterface;
class MyStorage implements StorageInterface
{
/** * @param string $key * @return mixed|null Null if the value is not found */publicfunctionget($key)
{
// implement get
}
/** * @param string $key * @param mixed $value */publicfunctionset($key, $value)
{
// implement set
}
/** * @param string $key * @since 2.0.0 */publicfunctionremove($key)
{
// implement remove
}
}Add the following to your app/Resources/config/routing.yml file:
opensoft_rollout:
resource: "@OpensoftRolloutBundle/Resources/config/routing.yml"
prefix: /admin/rollout
Check if a feature is enabled in a controller
if ($this->get('rollout')->isActive('chat', $this->getUser())) {
// do some chat related feature work
}Twig example:
{% if rollout_is_active('chat', app.user) %}
<!-- show a chat interface -->
{% endif %}




