Skip to content

Commit 89cd0c7

Browse files
committed
Added Symfony integration
1 parent d15ae11 commit 89cd0c7

6 files changed

Lines changed: 116 additions & 1 deletion

File tree

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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\Symfony\TogglerBundle(),
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

154180
To run the unit tests, execute the following command

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
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
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
3+
toggler.twig.extension:
4+
class: Toggler\Twig\Extension\ToggleExtension
5+
tags:
6+
- { name: twig.extension }

src/Symfony/TogglerBundle.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

0 commit comments

Comments
 (0)