File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -149,6 +149,32 @@ You can also use the `toggle()` function for conditions
149149{{ toggle('foo') ? 'Foo is enabled' : 'Foo is NOT enabled' }}
150150` ` `
151151
152+ # # Symfony Integration
153+
154+ Toggler comes with basic integration with the [Symfony](http://symfony.com/) framework.
155+ To enable toggler inside symfony, register the bundle
156+
157+ ` ` ` php
158+ // AppKernel.php
159+
160+ $bundles = array(
161+ ...
162+ new Toggler\S ymfony\T ogglerBundle(),
163+ ...
164+ );
165+ ` ` `
166+
167+ Then inside your `app/config/config.yml` or `app/config/config_dev.yml`, you can enable features using the following config
168+
169+ ` ` ` yaml
170+ toggler:
171+ config:
172+ foo: true
173+ bar: false
174+ ` ` `
175+
176+ When using the Symfony bundle, the twig extension is automatically registered.
177+
152178# # Testing
153179
154180To run the unit tests, execute the following command
Original file line number Diff line number Diff line change 2323 },
2424 "suggest" : {
2525 "twig/twig" : " To use the twig extension" ,
26- "symfony/yaml" : " To pass yml files to the config"
26+ "symfony/yaml" : " To pass yml files to the config" ,
27+ "symfony/symfony" : " To enable Symfony integration"
2728 }
2829}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the toggler project.
5+ *
6+ * @author pierre
7+ * @copyright Copyright (c) 2015
8+ */
9+
10+ namespace Toggler \Symfony \DependencyInjection ;
11+
12+ use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
13+ use Symfony \Component \Config \Definition \ConfigurationInterface ;
14+
15+ class Configuration implements ConfigurationInterface
16+ {
17+ /**
18+ * {@inheritdoc}
19+ */
20+ public function getConfigTreeBuilder ()
21+ {
22+ $ treeBuilder = new TreeBuilder ();
23+ $ rootNode = $ treeBuilder ->root ('toggler ' );
24+
25+ $ rootNode ->children ()
26+ ->arrayNode ('config ' )
27+ ->prototype ('boolean ' )
28+ ->end ()
29+ ->end ();
30+
31+ return $ treeBuilder ;
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the toggler project.
5+ *
6+ * @author pierre
7+ * @copyright Copyright (c) 2015
8+ */
9+
10+ namespace Toggler \Symfony \DependencyInjection ;
11+
12+ use Symfony \Component \Config \FileLocator ;
13+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
14+ use Symfony \Component \DependencyInjection \Loader ;
15+ use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
16+ use Toggler \Config ;
17+
18+ class TogglerExtension extends Extension
19+ {
20+ /**
21+ * {@inheritdoc}
22+ */
23+ public function load (array $ configs , ContainerBuilder $ container )
24+ {
25+ $ configuration = new Configuration ();
26+ $ config = $ this ->processConfiguration ($ configuration , $ configs );
27+
28+ Config::instance ()->setConfig (($ config ['config ' ]));
29+
30+ $ loader = new Loader \YamlFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config ' ));
31+ $ loader ->load ('services.yml ' );
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ services :
2+
3+ toggler.twig.extension :
4+ class : Toggler\Twig\Extension\ToggleExtension
5+ tags :
6+ - { name: twig.extension }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the toggler project.
5+ *
6+ * @author pierre
7+ * @copyright Copyright (c) 2015
8+ */
9+
10+ namespace Toggler \Symfony ;
11+
12+ use Symfony \Component \HttpKernel \Bundle \Bundle ;
13+
14+ class TogglerBundle extends Bundle
15+ {
16+ }
You can’t perform that action at this time.
0 commit comments