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
{
15 //Constructor required to derivate prefix from kernel.project_dir
16 public function __construct($projectDir) {
17 $this->projectDir
= $projectDir;
23 public function getConfigTreeBuilder() {
24 //Get TreeBuilder object
25 $treeBuilder = new TreeBuilder();
27 //Get ExecutableFinder object
28 $finder = new ExecutableFinder();
30 #TODO: see how we deal with asset url generation: see Rapsys/PackBundle/Twig/PackTokenParser.php +243
38 ## Force cache disable to regenerate resources each time
42 //TODO: see https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php for default value and description
43 //TODO: see http://symfony.com/doc/current/components/config/definition.html
44 //TODO: see https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
45 //TODO: use bin/console config:dump-reference to dump class infos
47 //The bundle default values
50 'prefix' => $this->projectDir
,
51 'scheme' => 'https://',
52 'timeout' => (int)ini_get('default_socket_timeout'),
53 'agent' => (string)ini_get('user_agent')?:'rapsys_pack/0.0.2',
57 'css' => 'css/*.pack.css',
58 'js' => 'js/*.pack.js',
59 'img' => 'img/*.pack.jpg'
63 'class' => 'Rapsys\PackBundle\Twig\Filter\CPackFilter',
64 'args' => [ $finder->find('cpack', '/usr/local/bin/cpack') ]
67 'class' => 'Rapsys\PackBundle\Twig\Filter\JPackFilter',
68 'args' => [ $finder->find('jpack', '/usr/local/bin/jpack') ]
71 'class' => 'Rapsys\PackBundle\Twig\Filter\IPackFilter',
77 //Here we define the parameters that are allowed to configure the bundle.
81 ->addDefaultsIfNotSet()
83 ->arrayNode('rapsys_pack')
84 ->addDefaultsIfNotSet()
88 ->addDefaultsIfNotSet()
90 ->scalarNode('prefix')->isRequired()->defaultValue($defaults['config']['prefix'])->end()
91 ->scalarNode('scheme')->isRequired()->defaultValue($defaults['config']['scheme'])->end()
92 ->integerNode('timeout')->isRequired()->min(0)->defaultValue($defaults['config']['timeout'])->end()
93 ->scalarNode('agent')->isRequired()->defaultValue($defaults['config']['agent'])->end()
94 ->integerNode('redirect')->isRequired()->min(1)->defaultValue($defaults['config']['redirect'])->end()
99 ->addDefaultsIfNotSet()
101 ->scalarNode('css')->isRequired()->defaultValue($defaults['output']['css'])->end()
102 ->scalarNode('js')->isRequired()->defaultValue($defaults['output']['js'])->end()
103 ->scalarNode('img')->isRequired()->defaultValue($defaults['output']['img'])->end()
106 ->arrayNode('filter')
108 ->addDefaultsIfNotSet()
111 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
112 ->addDefaultChildrenIfNoneSet()
115 ->scalarNode('class')
117 ->defaultValue($defaults['filter']['css']['class'])
121 ->treatNullLike(array())
122 ->defaultValue($defaults['filter']['css']['args'])
123 ->scalarPrototype()->end()
129 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
130 ->addDefaultChildrenIfNoneSet()
133 ->scalarNode('class')
135 ->defaultValue($defaults['filter']['js']['class'])
139 ->treatNullLike(array())
140 ->defaultValue($defaults['filter']['js']['args'])
141 ->scalarPrototype()->end()
147 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
148 ->addDefaultChildrenIfNoneSet()
151 ->scalarNode('class')
153 ->defaultValue($defaults['filter']['img']['class'])
157 ->treatNullLike(array())
158 ->defaultValue($defaults['filter']['img']['args'])
159 ->scalarPrototype()->end()