]> Raphaël G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
8f3beb23ff5f3f9cfad02b678bb80785838b023a
[packbundle] / DependencyInjection / Configuration.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys PackBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\PackBundle\DependencyInjection;
13
14 use Rapsys\PackBundle\RapsysPackBundle;
15
16 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17 use Symfony\Component\Config\Definition\ConfigurationInterface;
18 use Symfony\Component\DependencyInjection\Container;
19 use Symfony\Component\Process\ExecutableFinder;
20
21 /**
22 * {@inheritdoc}
23 *
24 * This is the class that validates and merges configuration from your app/config files.
25 *
26 * @link http://symfony.com/doc/current/cookbook/bundles/configuration.html
27 */
28 class Configuration implements ConfigurationInterface {
29 /**
30 * {@inheritdoc}
31 */
32 public function getConfigTreeBuilder(): TreeBuilder {
33 //Get TreeBuilder object
34 $treeBuilder = new TreeBuilder($alias = RapsysPackBundle::getAlias());
35
36 //Get ExecutableFinder object
37 $finder = new ExecutableFinder();
38
39 //The bundle default values
40 $defaults = [
41 //XXX: use a path relative to __DIR__ as console and index do not have the same execution directory
42 //XXX: use realpath on var/cache only as alias subdirectory may not yet exists
43 'cache' => realpath(dirname(__DIR__).'/../../../var/cache').'/'.$alias,
44 'captcha' => [
45 'background' => 'white',
46 'fill' => '#cff',
47 'height' => 52,
48 'size' => 45,
49 'border' => '#00c3f9',
50 'thickness' => 2,
51 'width' => 192
52 ],
53 'facebook' => [
54 'align' => 'center',
55 'fill' => 'white',
56 'font' => 'default',
57 'height' => 630,
58 'size' => 60,
59 'source' => dirname(__DIR__).'/public/facebook/source.png',
60 'border' => '#00c3f9',
61 'thickness' => 15,
62 'width' => 1200
63 ],
64 'filters' => [
65 'css' => [
66 0 => [
67 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
68 'args' => [
69 $finder->find('cpack', '/usr/local/bin/cpack'),
70 'minify'
71 ]
72 ]
73 ],
74 'img' => [
75 0 => [
76 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
77 'args' => []
78 ]
79 ],
80 'js' => [
81 0 => [
82 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
83 'args' => [
84 $finder->find('jpack', '/usr/local/bin/jpack'),
85 'best'
86 ]
87 ]
88 ]
89 ],
90 'fonts' => [
91 'default' => '/usr/share/fonts/TTF/dejavu/DejaVuSans.ttf',
92 #TODO: move these in veranda config ? with *: %rapsyspack.public%/woff2/*.woff2 ?
93 'droidsans' => dirname(__DIR__).'/public/woff2/droidsans.regular.woff2',
94 'droidsansb' => dirname(__DIR__).'/public/woff2/droidsans.bold.woff2',
95 'droidsansi' => dirname(__DIR__).'/public/woff2/droidserif.italic.woff2',
96 'droidsansm' => dirname(__DIR__).'/public/woff2/droidsansmono.regular.woff2',
97 'droidserif' => dirname(__DIR__).'/public/woff2/droidserif.regular.woff2',
98 'droidserifb' => dirname(__DIR__).'/public/woff2/droidserif.bold.woff2',
99 'droidserifbi' => dirname(__DIR__).'/public/woff2/droidserif.bolditalic.woff2',
100 'irishgrover' => dirname(__DIR__).'/public/woff2/irishgrover.v10.woff2',
101 'lemon' => dirname(__DIR__).'/public/woff2/lemon.woff2',
102 'notoemoji' => dirname(__DIR__).'/public/woff2/notoemoji.woff2'
103 ],
104 'map' => [
105 'border' => '#00c3f9',
106 'fill' => '#cff',
107 'height' => 640,
108 'quality' => 70,
109 'radius' => 5,
110 'server' => 'osm',
111 'thickness' => 2,
112 'tz' => 256,
113 'width' => 640,
114 'zoom' => 17
115 ],
116 'multi' => [
117 'border' => '#00c3f9',
118 'fill' => '#cff',
119 'height' => 640,
120 'highborder' => '#3333c3',
121 'highfill' => '#c3c3f9',
122 'highradius' => 6,
123 'highsize' => 30,
124 'highthickness' => 4,
125 'quality' => 70,
126 'radius' => 5,
127 'server' => 'osm',
128 'size' => 20,
129 'thickness' => 2,
130 'tz' => 256,
131 'width' => 640,
132 'zoom' => 17
133 ],
134 'prefixes' => [
135 'captcha' => 'captcha',
136 'css' => 'css',
137 'facebook' => 'facebook',
138 'img' => 'img',
139 'map' => 'map',
140 'multi' => 'multi',
141 'pack' => 'pack',
142 'thumb' => 'thumb',
143 'js' => 'js'
144 ],
145 //XXX: use a path relative to __DIR__ as console and index do not have the same execution directory
146 'public' => dirname(__DIR__).'/public',
147 'routes' => [
148 'css' => 'rapsyspack_css',
149 'img' => 'rapsyspack_img',
150 'js' => 'rapsyspack_js'
151 ],
152 'servers' => [
153 'cycle' => 'http://a.tile.thunderforest.com/cycle/{Z}/{X}/{Y}.png',
154 'osm' => 'https://tile.openstreetmap.org/{Z}/{X}/{Y}.png',
155 'transport' => 'http://a.tile.thunderforest.com/transport/{Z}/{X}/{Y}.png'
156 ],
157 'thumb' => [
158 'height' => 128,
159 'width' => 128
160 ],
161 'tokens' => [
162 'css' => 'asset',
163 'img' => 'asset',
164 'js' => 'asset'
165 ]
166 ];
167
168 /**
169 * Defines parameters allowed to configure the bundle
170 *
171 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
172 * @link http://symfony.com/doc/current/components/config/definition.html
173 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
174 *
175 * @see bin/console config:dump-reference rapsyspack to dump default config
176 * @see bin/console debug:config rapsyspack to dump config
177 */
178 $treeBuilder
179 //Parameters
180 ->getRootNode()
181 ->addDefaultsIfNotSet()
182 ->children()
183 ->scalarNode('cache')->cannotBeEmpty()->defaultValue($defaults['cache'])->end()
184 ->arrayNode('captcha')
185 ->addDefaultsIfNotSet()
186 ->children()
187 ->scalarNode('background')->cannotBeEmpty()->defaultValue($defaults['captcha']['background'])->end()
188 ->scalarNode('fill')->cannotBeEmpty()->defaultValue($defaults['captcha']['fill'])->end()
189 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['captcha']['height'])->end()
190 ->scalarNode('size')->cannotBeEmpty()->defaultValue($defaults['captcha']['size'])->end()
191 ->scalarNode('border')->cannotBeEmpty()->defaultValue($defaults['captcha']['border'])->end()
192 ->scalarNode('thickness')->cannotBeEmpty()->defaultValue($defaults['captcha']['thickness'])->end()
193 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['captcha']['width'])->end()
194 ->end()
195 ->end()
196 ->arrayNode('facebook')
197 ->addDefaultsIfNotSet()
198 ->children()
199 ->scalarNode('align')->cannotBeEmpty()->defaultValue($defaults['facebook']['align'])->end()
200 ->scalarNode('fill')->cannotBeEmpty()->defaultValue($defaults['facebook']['fill'])->end()
201 ->scalarNode('font')->cannotBeEmpty()->defaultValue($defaults['facebook']['font'])->end()
202 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['facebook']['height'])->end()
203 ->scalarNode('size')->cannotBeEmpty()->defaultValue($defaults['facebook']['size'])->end()
204 ->scalarNode('source')->cannotBeEmpty()->defaultValue($defaults['facebook']['source'])->end()
205 ->scalarNode('border')->cannotBeEmpty()->defaultValue($defaults['facebook']['border'])->end()
206 ->scalarNode('thickness')->cannotBeEmpty()->defaultValue($defaults['facebook']['thickness'])->end()
207 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['facebook']['width'])->end()
208 ->end()
209 ->end()
210 ->arrayNode('filters')
211 ->addDefaultsIfNotSet()
212 ->children()
213 ->arrayNode('css')
214 /**
215 * Undocumented
216 *
217 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
218 */
219 ->addDefaultChildrenIfNoneSet()
220 ->arrayPrototype()
221 ->children()
222 ->scalarNode('class')
223 ->isRequired()
224 ->cannotBeEmpty()
225 ->defaultValue($defaults['filters']['css'][0]['class'])
226 ->end()
227 ->arrayNode('args')
228 //->isRequired()
229 ->treatNullLike([])
230 ->defaultValue($defaults['filters']['css'][0]['args'])
231 ->scalarPrototype()->end()
232 ->end()
233 ->end()
234 ->end()
235 ->end()
236 ->arrayNode('img')
237 /**
238 * Undocumented
239 *
240 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
241 */
242 ->addDefaultChildrenIfNoneSet()
243 ->arrayPrototype()
244 ->children()
245 ->scalarNode('class')
246 ->isRequired()
247 ->cannotBeEmpty()
248 ->defaultValue($defaults['filters']['img'][0]['class'])
249 ->end()
250 ->arrayNode('args')
251 ->treatNullLike([])
252 ->defaultValue($defaults['filters']['img'][0]['args'])
253 ->scalarPrototype()->end()
254 ->end()
255 ->end()
256 ->end()
257 ->end()
258 ->arrayNode('js')
259 /**
260 * Undocumented
261 *
262 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
263 */
264 ->addDefaultChildrenIfNoneSet()
265 ->arrayPrototype()
266 ->children()
267 ->scalarNode('class')
268 ->isRequired()
269 ->cannotBeEmpty()
270 ->defaultValue($defaults['filters']['js'][0]['class'])
271 ->end()
272 ->arrayNode('args')
273 ->treatNullLike([])
274 ->defaultValue($defaults['filters']['js'][0]['args'])
275 ->scalarPrototype()->end()
276 ->end()
277 ->end()
278 ->end()
279 ->end()
280 ->end()
281 ->end()
282 ->arrayNode('fonts')
283 ->treatNullLike([])
284 ->defaultValue($defaults['fonts'])
285 ->scalarPrototype()->end()
286 ->end()
287 ->arrayNode('map')
288 ->addDefaultsIfNotSet()
289 ->children()
290 ->scalarNode('border')->cannotBeEmpty()->defaultValue($defaults['map']['border'])->end()
291 ->scalarNode('fill')->cannotBeEmpty()->defaultValue($defaults['map']['fill'])->end()
292 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['map']['height'])->end()
293 ->scalarNode('quality')->cannotBeEmpty()->defaultValue($defaults['map']['quality'])->end()
294 ->scalarNode('radius')->cannotBeEmpty()->defaultValue($defaults['map']['radius'])->end()
295 ->scalarNode('server')->cannotBeEmpty()->defaultValue($defaults['map']['server'])->end()
296 ->scalarNode('thickness')->cannotBeEmpty()->defaultValue($defaults['map']['thickness'])->end()
297 ->scalarNode('tz')->cannotBeEmpty()->defaultValue($defaults['map']['tz'])->end()
298 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['map']['width'])->end()
299 ->scalarNode('zoom')->cannotBeEmpty()->defaultValue($defaults['map']['zoom'])->end()
300 ->end()
301 ->end()
302 ->arrayNode('multi')
303 ->addDefaultsIfNotSet()
304 ->children()
305 ->scalarNode('border')->cannotBeEmpty()->defaultValue($defaults['multi']['border'])->end()
306 ->scalarNode('fill')->cannotBeEmpty()->defaultValue($defaults['multi']['fill'])->end()
307 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['multi']['height'])->end()
308 ->scalarNode('highborder')->cannotBeEmpty()->defaultValue($defaults['multi']['highborder'])->end()
309 ->scalarNode('highfill')->cannotBeEmpty()->defaultValue($defaults['multi']['highfill'])->end()
310 ->scalarNode('highradius')->cannotBeEmpty()->defaultValue($defaults['multi']['highradius'])->end()
311 ->scalarNode('highsize')->cannotBeEmpty()->defaultValue($defaults['multi']['highsize'])->end()
312 ->scalarNode('highthickness')->cannotBeEmpty()->defaultValue($defaults['multi']['highthickness'])->end()
313 ->scalarNode('quality')->cannotBeEmpty()->defaultValue($defaults['multi']['quality'])->end()
314 ->scalarNode('radius')->cannotBeEmpty()->defaultValue($defaults['multi']['radius'])->end()
315 ->scalarNode('server')->cannotBeEmpty()->defaultValue($defaults['multi']['server'])->end()
316 ->scalarNode('size')->cannotBeEmpty()->defaultValue($defaults['multi']['size'])->end()
317 ->scalarNode('thickness')->cannotBeEmpty()->defaultValue($defaults['multi']['thickness'])->end()
318 ->scalarNode('tz')->cannotBeEmpty()->defaultValue($defaults['multi']['tz'])->end()
319 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['multi']['width'])->end()
320 ->scalarNode('zoom')->cannotBeEmpty()->defaultValue($defaults['multi']['zoom'])->end()
321 ->end()
322 ->end()
323 ->arrayNode('prefixes')
324 ->treatNullLike([])
325 ->defaultValue($defaults['prefixes'])
326 ->scalarPrototype()->end()
327 ->end()
328 ->scalarNode('public')->cannotBeEmpty()->defaultValue($defaults['public'])->end()
329 ->arrayNode('routes')
330 ->addDefaultsIfNotSet()
331 ->children()
332 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['routes']['css'])->end()
333 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['routes']['img'])->end()
334 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['routes']['js'])->end()
335 ->end()
336 ->end()
337 ->arrayNode('servers')
338 ->treatNullLike([])
339 ->defaultValue($defaults['servers'])
340 ->scalarPrototype()->end()
341 ->end()
342 ->arrayNode('thumb')
343 ->addDefaultsIfNotSet()
344 ->children()
345 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['thumb']['height'])->end()
346 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['thumb']['width'])->end()
347 ->end()
348 ->end()
349 ->arrayNode('tokens')
350 ->addDefaultsIfNotSet()
351 ->children()
352 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['tokens']['css'])->end()
353 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['tokens']['img'])->end()
354 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['tokens']['js'])->end()
355 ->end()
356 ->end()
357 ->end()
358 ->end();
359
360 return $treeBuilder;
361 }
362 }