]> Raphaƫl G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
341f178a8fceb01cb2e9fe3f208d9d3dabc5a762
[packbundle] / DependencyInjection / Configuration.php
1 <?php
2
3 namespace Rapsys\PackBundle\DependencyInjection;
4
5 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6 use Symfony\Component\Config\Definition\ConfigurationInterface;
7 use Symfony\Component\Process\ExecutableFinder;
8
9 /**
10 * This is the class that validates and merges configuration from your app/config files.
11 *
12 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
13 */
14 class Configuration implements ConfigurationInterface {
15 //Constructor required to derivate prefix from kernel.project_dir
16 public function __construct($projectDir) {
17 $this->projectDir = $projectDir;
18 }
19
20 /**
21 * {@inheritdoc}
22 */
23 public function getConfigTreeBuilder() {
24 //Get TreeBuilder object
25 $treeBuilder = new TreeBuilder();
26
27 //Get ExecutableFinder object
28 $finder = new ExecutableFinder();
29
30 #TODO: see how we deal with asset url generation: see Rapsys/PackBundle/Twig/PackTokenParser.php +243
31 #framework:
32 # assets:
33 # packages:
34 # rapsys_pack:
35 # base_path: '/'
36 # version: ~
37 #
38 ## Force cache disable to regenerate resources each time
39 ##twig:
40 ## cache: ~
41
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
46
47 //The bundle default values
48 $defaults = [
49 'config' => [
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',
54 'redirect' => 5
55 ],
56 'output' => [
57 'css' => 'css/*.pack.css',
58 'js' => 'js/*.pack.js',
59 'img' => 'img/*.pack.jpg'
60 ],
61 'filter' => [
62 'css' => [
63 'class' => 'Rapsys\PackBundle\Twig\Filter\CPackFilter',
64 'args' => [ $finder->find('cpack', '/usr/local/bin/cpack') ]
65 ],
66 'js' => [
67 'class' => 'Rapsys\PackBundle\Twig\Filter\JPackFilter',
68 'args' => [ $finder->find('jpack', '/usr/local/bin/jpack') ]
69 ],
70 'img' => [
71 'class' => 'Rapsys\PackBundle\Twig\Filter\IPackFilter',
72 'args' => []
73 ],
74 ]
75 ];
76
77 //Here we define the parameters that are allowed to configure the bundle.
78 $treeBuilder
79 //Parameters
80 ->root('parameters')
81 ->addDefaultsIfNotSet()
82 ->children()
83 ->arrayNode('rapsys_pack')
84 ->addDefaultsIfNotSet()
85 ->children()
86 ->arrayNode('config')
87 ->isRequired()
88 ->addDefaultsIfNotSet()
89 ->children()
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()
95 ->end()
96 ->end()
97 ->arrayNode('output')
98 ->isRequired()
99 ->addDefaultsIfNotSet()
100 ->children()
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()
104 ->end()
105 ->end()
106 ->arrayNode('filter')
107 ->isRequired()
108 ->addDefaultsIfNotSet()
109 ->children()
110 ->arrayNode('css')
111 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
112 ->addDefaultChildrenIfNoneSet()
113 ->arrayPrototype()
114 ->children()
115 ->scalarNode('class')
116 ->isRequired()
117 ->defaultValue($defaults['filter']['css']['class'])
118 ->end()
119 ->arrayNode('args')
120 ->isRequired()
121 ->treatNullLike(array())
122 ->defaultValue($defaults['filter']['css']['args'])
123 ->scalarPrototype()->end()
124 ->end()
125 ->end()
126 ->end()
127 ->end()
128 ->arrayNode('js')
129 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
130 ->addDefaultChildrenIfNoneSet()
131 ->arrayPrototype()
132 ->children()
133 ->scalarNode('class')
134 ->isRequired()
135 ->defaultValue($defaults['filter']['js']['class'])
136 ->end()
137 ->arrayNode('args')
138 ->isRequired()
139 ->treatNullLike(array())
140 ->defaultValue($defaults['filter']['js']['args'])
141 ->scalarPrototype()->end()
142 ->end()
143 ->end()
144 ->end()
145 ->end()
146 ->arrayNode('img')
147 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
148 ->addDefaultChildrenIfNoneSet()
149 ->arrayPrototype()
150 ->children()
151 ->scalarNode('class')
152 ->isRequired()
153 ->defaultValue($defaults['filter']['img']['class'])
154 ->end()
155 ->arrayNode('args')
156 ->isRequired()
157 ->treatNullLike(array())
158 ->defaultValue($defaults['filter']['img']['args'])
159 ->scalarPrototype()->end()
160 ->end()
161 ->end()
162 ->end()
163 ->end()
164 ->end()
165 ->end()
166 ->end()
167 ->end()
168 ->end()
169 ->end();
170
171 return $treeBuilder;
172 }
173 }