2017 © Pedro Peláez
 

symfony-bundle toggle-bundle

This Bundle provides the integration with qandidate/toggle. It provides the services and configuration you need to implement feature toggles in your Symfony application.

image

qandidate/toggle-bundle

This Bundle provides the integration with qandidate/toggle. It provides the services and configuration you need to implement feature toggles in your Symfony application.

  • Wednesday, December 20, 2017
  • by asm89
  • Repository
  • 10 Watchers
  • 72 Stars
  • 169,600 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 22 Forks
  • 2 Open issues
  • 13 Versions
  • 8 % Grown

The README.md

Qandidate Toggle Symfony Bundle

This Bundle provides the integration with our toggle library. It provides the services and configuration you need to implement feature toggles in your application., (*1)

build status, (*2)

About

Read the our blog post series about this repository at: - http://labs.qandidate.com/blog/2014/08/18/a-new-feature-toggling-library-for-php/ - http://labs.qandidate.com/blog/2014/08/19/open-sourcing-our-feature-toggle-api-and-ui/, (*3)

Installation

Using Symfony Flex

The easiest way to install and configure the QandidateToggleBundle with Symfony is by using Symfony Flex., (*4)

Make sure you have Symfony Flex installed:, (*5)

$ composer require symfony/flex ^1.0
$ composer config extra.symfony.allow-contrib true

Install the bundle:, (*6)

$ composer require qandidate/toggle-bundle ^1.0

Symfony Flex will automatically register and configure the bundle., (*7)

Manually

Add the bundle to your composer.json, (*8)

$ composer require qandidate/toggle-bundle ^1.0

Add the bundle to your Kernel:, (*9)

$bundles = array(
    // ..
    new Symfony\Bundle\SecurityBundle\SecurityBundle(),
    new Symfony\Bundle\TwigBundle\TwigBundle(),
    new Qandidate\Bundle\ToggleBundle\QandidateToggleBundle(),
);

Configuration

qandidate_toggle:
    persistence: in_memory|redis|factory|config
    context_factory: null|your.context_factory.service.id
    redis_namespace: toggle_%kernel.environment% # default, only required when persistence = redis
    redis_client: null|your.redis_client.service.id # only required when persistence = redis
    collection_factory: # only required when persistence = factory
        service_id: your.collection_factory.service.id
        method: create

Sample Configuration for Symfony

qandidate_toggle:
    persistence: config
    toggles:
      always-active-feature:
        name: always-active-feature
        status: always-active
      inactive-feature:
        name: inactive-feature
        status: inactive
        conditions: 
      conditionally-active:
        name: conditionally-active
        status: conditionally-active
        conditions:
         - name: operator-condition
           key: user_id
           operator:
               name: greater-than
               value: 42

Example usage

Usage can vary on your application. This example uses the supplied UserContextFactory, but you probably need to create your own factory., (*10)



<service id="acme.controller" class="Acme\Controller">
    <argument type="service" id="qandidate.toggle.manager" />
    <argument type="service" id="qandidate.toggle.user_context_factory" />
</service>
// Acme\Controller

public function __construct(
    /* ArticleRepository, Templating, ..*/ 
    ToggleManager $manager, 
    ContextFactory $contextFactory
) {
    // ..
    $this->manager = $manager;
    $this->context = $contextFactory->createContext();
}

// ..

public function articleAction(Request $request)
{
    $this->article = $this->repository->findBySlug($request->request->get('slug'));

    return $this->templating->render('article.html.twig', array(
        'article'        => $article,
        'enableComments' => $this->manager->active('comments', $this->context),
    ));
}

You can find a working example using the Symfony MicroKernelTrait in the Resources/doc/example directory., (*11)

Annotation Usage

You can also use the @Toggle annotation on a controller. When the toggle isn't active a 404 exception is thrown., (*12)

use Qandidate\Bundle\ToggleBundle\Annotations\Toggle;

/**
 * @Toggle("cool-feature")
 */
class FooController
{

    /**
     * @Toggle("another-cool-feature")
     */
    public function barAction()
    {
    }

    public function bazAction()
    {
    }
}

Twig usage

If you use Twig you can also use the function:, (*13)

{% if feature_is_active('comments') %}
    {# Awesome comments #}
{% endif %}

Or the Twig test:, (*14)

{% if 'comments' is active feature %}
    {# Awesome comments #}
{% endif %}

Both are registered in the ToggleTwigExtension., (*15)

Data collector

With the data collector you have a overview about all toggles. In the toolbar you see all conditions and the current status., (*16)

In the panel you have two lists:, (*17)

  • You can see all keys and there current values.
  • Then you can see all configured toggles, there conditions and if they are active.

Testing

To run PHPUnit tests:, (*18)

$ ./vendor/bin/phpunit

License

MIT, see LICENSE., (*19)

The Versions

13/12 2017

1.0.1

1.0.1.0

This Bundle provides the integration with qandidate/toggle. It provides the services and configuration you need to implement feature toggles in your Symfony application.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Willem-Jan

10/12 2017

1.0.0

1.0.0.0

This Bundle provides the integration with qandidate/toggle. It provides the services and configuration you need to implement feature toggles in your Symfony application.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Willem-Jan

21/10 2017

0.8.0

0.8.0.0

This Bundle provides the integration with qandidate/toggle. It provides the services and configuration you need to implement feature toggles in your Symfony application.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Willem-Jan

24/07 2017

0.7.0

0.7.0.0

This Bundle provides the integration with qandidate/toggle. It provides the services and configuration you need to implement feature toggles in your Symfony application.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Willem-Jan

07/05 2017

0.6.0

0.6.0.0

This Bundle provides the integration with qandidate/toggle. It provides the services and configuration you need to implement feature toggles in your Symfony application.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Willem-Jan

14/06 2016

0.5.0

0.5.0.0

This Bundle provides the integration with qandidate/toggle. It provides the services and configuration you need to implement feature toggles in your Symfony application.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Willem-Jan

04/03 2016

0.4.0

0.4.0.0

This Bundle provides the integration with qandidate/toggle. It provides the services and configuration you need to implement feature toggles in your Symfony application.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Willem-Jan