Code Monkey home page Code Monkey logo

opensoftrolloutbundle's Introduction

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 (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 Rollout UserProviderInterface
  • storage_service: Defaults to Opensoft\Rollout\Storage\ArrayStorage, but you can also use the included Opensoft\RolloutBundle\Storage\Doctrine\DoctrineORMStorage 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

opensoftrolloutbundle's People

Contributors

4rthem avatar angelsk avatar filipgolonka avatar richardfullmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

opensoftrolloutbundle's Issues

Caching doctrine storage

When using DoctrineORMStorage, if multiple check on the same feature happens several times multiple queries are made to load the feature.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.