Developed with love by KnpLabs Hire us for your project!
49

OpensoftRolloutBundle

by opensoft

A Symfony2 Bundle for opensoft/rollout

OpensoftRolloutBundle

A Symfony3 Bundle for opensoft/rollout

Build Status Scrutinizer Code Quality Code Coverage Total Downloads Latest Stable Version

Obligatory Screenshot

Screenshot

Installation

1) Install via composer

Add the bundle via composer

composer require opensoft/rollout-bundle

And activate it inside your app\AppKernel.php

new Opensoft\RolloutBundle\OpensoftRolloutBundle(),

2) Configuration

Add the following to your configuration

opensoft_rollout:
    user_provider_service: [YOUR USER PROVIDER SERVICE ID]
    storage_service: [YOUR STORAGE SERVICE FOR ROLLOUT]
  • user_provider_service: If you are using one of the default Symfony user providers you can get the service ID by running bin/console debug:container provider e.g: security.user.provider.ldap
  • storage_service: Defaults to rollout.storage.array_storage, but you can also use the included rollout.storage.doctrine_orm_storage or create your own (see below for implementation)

3) Implement Interfaces

RolloutUserInterface

Any rollout user must implement the RolloutUserInterface. Often, this will be your main user object in the application.

<?php

use Opensoft/Rollout/RolloutUserInterface;

class User implements RolloutUserInterface
{
    /**
     * @return string
     */
    public function getRolloutIdentifier()
    {
        return $this->email;
    }
}

UserProviderInterface

Expose individual users to the rollout interface by implementing the UserProviderInterface

<?php

use Doctrine\ORM\EntityRepository;
use Opensoft\RolloutBundle\Rollout\UserProviderInterface;

class UserRepository extends EntityRepository implements UserProviderInterface
{
    /**
     * @param  mixed $id
     * @return RolloutUserInterface|null
     */
    public function findByRolloutIdentifier($id)
    {
        return $this->findOneBy(array('email' => $id));
    }
}

GroupDefinitionInterface

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

<?php

use Opensoft\RolloutBundle\Rollout\GroupDefinitionInterface;

class AcmeEmployeeGroupDefinition implements GroupDefinitionInterface
{
    /**
     * @return string
     */
    public function getName()
    {
        return 'acme_employee';
    }

    /**
     * @return string
     */
    public function getDescription()
    {
        return 'This group contains acme company employees';
    }

    /**
     * @return \Closure
     */
    public function getCallback()
    {
        return function(RolloutUserInterface $user) {
            // Is this user an employee of acme?
            return strpos($user->getEmail(), 'acme.com') !== false;
        };
    }
}

StorageInterface

Implement a custom storage solution.

Note: The rollout StorageInterface changed in version 2.0.0.

<?php

use Opensoft\Rollout\Storage\StorageInterface;

class MyStorage implements StorageInterface
{
    /**
     * @param  string     $key
     * @return mixed|null Null if the value is not found
     */
    public function get($key)
    {
        // implement get
    }

    /**
     * @param string $key
     * @param mixed  $value
     */
    public function set($key, $value)
    {
        // implement set
    }

    /**
     * @param string $key
     * @since 2.0.0
     */
    public function remove($key)
    {
        // implement remove
    }
}

4) Activate Routing

Add the following to your app/Resources/config/routing.yml file:

opensoft_rollout:
    resource: "@OpensoftRolloutBundle/Resources/config/routing.yml"
    prefix:   /admin/rollout

Usage

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 %}

Further Reading

Copyright (c) 2014 Opensoft

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
opensoft_rollout:
user_provider_service: ~ # Required
storage_service: rollout.storage.array_storage
  • Merge pull request #6 from angelsk/master
    By web-flow, 3 months ago
  • Removing PHP5.3 as it's not running as standard on Travis
    By , 3 months ago
  • Adding more information on the parameters and avoid reference to acme demo bundle
    By angelsk, 3 months ago
  • Bootstrap JS requires JQuery
    By angelsk, 3 months ago
  • Merge pull request #5 from 4rthem/sf-3
    By web-flow, 1 year ago
  • remove hhvm from travis
    By 4rthem, 1 year ago
  • upgrade to symfony 3
    By 4rthem, 1 year ago
  • Merge pull request #1 from filipgolonka/edit_request_param
    By web-flow, 1 year ago
  • Merge pull request #3 from filipgolonka/additional_php_versions
    By web-flow, 1 year ago
  • Additional PHP versions on travis
    By filipgolonka, 1 year ago
  • Edit request param
    By filipgolonka, 1 year ago
  • Adding support for removing features
    By richardfullmer, 2 years ago
  • Update documentation and controller
    By richardfullmer, 4 years ago
  • Use opensoft/rollout stable
    By richardfullmer, 4 years ago
  • Add scrutinizer badges
    By richardfullmer, 4 years ago
  • Add travis build status
    By richardfullmer, 4 years ago
  • Add a simple first test
    By richardfullmer, 4 years ago
  • Add phpunit to composer's require-dev
    By richardfullmer, 4 years ago
  • Set the minimum stability to dev
    By richardfullmer, 4 years ago
  • Add description to composer.json
    By richardfullmer, 4 years ago
  • Initial commit
    By richardfullmer, 4 years ago