Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feature Toggles in Symfony

Tags:

php

symfony

Our Symfony application is currently one application, that will soon require ability to have multiple sites point to the same Symfony core and have slightly different functionality based on which site it is currently on.

As an example we might have a banner showing on one site but not another. Another example is a payment option that will be enabled/disabled on the different sites. Or another one is different fields on a form on the different sites.

Has anybody had experience structuring Symfony application in this way?

like image 487
Scott Warren Avatar asked Sep 23 '14 03:09

Scott Warren


3 Answers

If you want to "theme" your application you can use the LiipThemeBundle, it really works well. For the features activation/deactivation you also have the FeatureToggleBundle bundle (quiet recent).

You could also implement a basic helper like this:

/**
 * Check if a feature is activated.
 *
 * @param string $feature Name of the feature
 *
 * @throws AccessDeniedHttpException
 */
protected function checkFeature($feature)
{
    $features = $this->container->getParameter('app.features')
    if (!$features[$feature]) {
        throw new AccessDeniedHttpException();
    }
}

...

$this->checkFeature('contact_form');

With this kind of configuration:

app.features:
    contact_form: false
like image 186
COil Avatar answered Nov 05 '22 23:11

COil


You have to know that using kernel event listener you can do most of the work.

You can in a 'CoreBundle' for example refer the user to a different template depending on the domain name where he is, using the kernel.request event.

So in your situation it would be easy for a site to showing a banner in a site but not another.

You can look this article that explains it :

Twig templating using event listener

like image 21
PASTAGA Avatar answered Nov 05 '22 22:11

PASTAGA


Yess thats the advantage of symfony

enter image description here

symfony use the kernel connected with routing and controller and then response is being created.

If you want to use multiple applications in symfony you can do this very easily and that is an advantage of symfony.For this you just need to add some routing and everything will be done automatically.

You can use symfony form class to add forms and append them to other pages with required field without creating whole form again. If you want to add or remove some features on/off you can just do this by app class or by creating different controllers.

like image 2
StaticVariable Avatar answered Nov 06 '22 00:11

StaticVariable