3 namespace Rapsys\PackBundle\DependencyInjection
;
5 use Symfony\Component\Config\Definition\Builder\TreeBuilder
;
6 use Symfony\Component\Config\Definition\ConfigurationInterface
;
7 use Symfony\Component\Process\ExecutableFinder
;
10 * This is the class that validates and merges configuration from your app/config files.
12 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
14 class Configuration
implements ConfigurationInterface
{
18 //Constructor required to derivate prefix from kernel.project_dir
19 public function __construct($projectDir) {
20 $this->projectDir
= $projectDir;
26 public function getConfigTreeBuilder() {
27 //Get TreeBuilder object
28 $treeBuilder = new TreeBuilder('rapsys_pack');
30 //Get ExecutableFinder object
31 $finder = new ExecutableFinder();
33 #TODO: see how we deal with asset url generation: see Rapsys/PackBundle/Twig/PackTokenParser.php +243
41 ## Force cache disable to regenerate resources each time
45 //TODO: see https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php for default value and description
46 //TODO: see http://symfony.com/doc/current/components/config/definition.html
47 //TODO: see https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
48 //TODO: use bin/console config:dump-reference to dump class infos
50 //The bundle default values
53 'prefix' => $this->projectDir
,
54 'name' => 'asset_url',
55 'scheme' => 'https://',
56 'timeout' => (int)ini_get('default_socket_timeout'),
57 'agent' => (string)ini_get('user_agent')?:'rapsys_pack/0.1.1',
61 'css' => 'css/*.pack.css',
62 'js' => 'js/*.pack.js',
63 'img' => 'img/*.pack.jpg'
67 'class' => 'Rapsys\PackBundle\Twig\Filter\CPackFilter',
69 $finder->find('cpack', '/usr/local/bin/cpack'),
74 'class' => 'Rapsys\PackBundle\Twig\Filter\JPackFilter',
76 $finder->find('jpack', '/usr/local/bin/jpack'),
81 'class' => 'Rapsys\PackBundle\Twig\Filter\IPackFilter',
87 //Here we define the parameters that are allowed to configure the bundle.
91 ->addDefaultsIfNotSet()
94 ->addDefaultsIfNotSet()
96 ->scalarNode('prefix')->cannotBeEmpty()->defaultValue($defaults['config']['prefix'])->end()
97 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['config']['name'])->end()
98 ->scalarNode('scheme')->cannotBeEmpty()->defaultValue($defaults['config']['scheme'])->end()
99 ->integerNode('timeout')->min(0)->max(300)->defaultValue($defaults['config']['timeout'])->end()
100 ->scalarNode('agent')->cannotBeEmpty()->defaultValue($defaults['config']['agent'])->end()
101 ->integerNode('redirect')->min(1)->max(30)->defaultValue($defaults['config']['redirect'])->end()
104 ->arrayNode('output')
105 ->addDefaultsIfNotSet()
107 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['output']['css'])->end()
108 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['output']['js'])->end()
109 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['output']['img'])->end()
112 ->arrayNode('filters')
113 ->addDefaultsIfNotSet()
116 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
117 ->addDefaultChildrenIfNoneSet()
120 ->scalarNode('class')
123 ->defaultValue($defaults['filters']['css']['class'])
127 ->treatNullLike(array())
128 ->defaultValue($defaults['filters']['css']['args'])
129 ->scalarPrototype()->end()
135 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
136 ->addDefaultChildrenIfNoneSet()
139 ->scalarNode('class')
142 ->defaultValue($defaults['filters']['js']['class'])
145 ->treatNullLike(array())
146 ->defaultValue($defaults['filters']['js']['args'])
147 ->scalarPrototype()->end()
153 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
154 ->addDefaultChildrenIfNoneSet()
157 ->scalarNode('class')
160 ->defaultValue($defaults['filters']['img']['class'])
163 ->treatNullLike(array())
164 ->defaultValue($defaults['filters']['img']['args'])
165 ->scalarPrototype()->end()