2017 © Pedro Peláez
 

symfony-bundle toggle-bundle

image

tsslabs/toggle-bundle

  • Monday, November 30, 2015
  • by radutopala
  • Repository
  • 1 Watchers
  • 0 Stars
  • 440 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 22 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % 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

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

$ composer require qandidate/toggle-bundle ~0.1

Add the bundle to your Kernel, (*5)

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

Configuration

qandidate_toggle:
    persistence: in_memory|redis
    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

Example usage

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



<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),
    ));
}

Twig usage

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

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

License

MIT, see LICENSE., (*8)

The Versions