]> Raphaël G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
Move stream context array in context parameter
[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 'context' => [
54 'http' => [
55 'max_redirects' => $_ENV['RAPSYSPACK_REDIRECT'] ?? 20,
56 'timeout' => $_ENV['RAPSYSPACK_TIMEOUT'] ?? (($timeout = ini_get('default_socket_timeout')) !== false && $timeout !== '' ? (float)$timeout : 60),
57 'user_agent' => $_ENV['RAPSYSPACK_AGENT'] ?? (($agent = ini_get('user_agent')) !== false && $agent !== '' ? (string)$agent : $alias.'/'.($version = RapsysPackBundle::getVersion()))
58 ]
59 ],
60 'facebook' => [
61 'align' => 'center',
62 'fill' => 'white',
63 'font' => 'default',
64 'height' => 630,
65 'size' => 60,
66 'source' => dirname(__DIR__).'/public/facebook/source.png',
67 'border' => '#00c3f9',
68 'thickness' => 15,
69 'width' => 1200
70 ],
71 'filters' => [
72 'css' => [
73 0 => [
74 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
75 'args' => [
76 $finder->find('cpack', '/usr/local/bin/cpack'),
77 'minify'
78 ]
79 ]
80 ],
81 'img' => [
82 0 => [
83 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
84 'args' => []
85 ]
86 ],
87 'js' => [
88 0 => [
89 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
90 'args' => [
91 $finder->find('jpack', '/usr/local/bin/jpack'),
92 'best'
93 ]
94 ]
95 ]
96 ],
97 'fonts' => [
98 'default' => '/usr/share/fonts/TTF/dejavu/DejaVuSans.ttf',
99 #TODO: move these in veranda config ? with *: %rapsyspack.public%/woff2/*.woff2 ?
100 'droidsans' => dirname(__DIR__).'/public/woff2/droidsans.regular.woff2',
101 'droidsansb' => dirname(__DIR__).'/public/woff2/droidsans.bold.woff2',
102 'droidsansi' => dirname(__DIR__).'/public/woff2/droidserif.italic.woff2',
103 'droidsansm' => dirname(__DIR__).'/public/woff2/droidsansmono.regular.woff2',
104 'droidserif' => dirname(__DIR__).'/public/woff2/droidserif.regular.woff2',
105 'droidserifb' => dirname(__DIR__).'/public/woff2/droidserif.bold.woff2',
106 'droidserifbi' => dirname(__DIR__).'/public/woff2/droidserif.bolditalic.woff2',
107 'irishgrover' => dirname(__DIR__).'/public/woff2/irishgrover.v10.woff2',
108 'lemon' => dirname(__DIR__).'/public/woff2/lemon.woff2',
109 'notoemoji' => dirname(__DIR__).'/public/woff2/notoemoji.woff2'
110 ],
111 'map' => [
112 'border' => '#00c3f9',
113 'fill' => '#cff',
114 'height' => 640,
115 'quality' => 70,
116 'radius' => 5,
117 'server' => 'osm',
118 'thickness' => 2,
119 'tz' => 256,
120 'width' => 640,
121 'zoom' => 17
122 ],
123 'multi' => [
124 'border' => '#00c3f9',
125 'fill' => '#cff',
126 'height' => 640,
127 'highborder' => '#3333c3',
128 'highfill' => '#c3c3f9',
129 'highradius' => 6,
130 'highsize' => 30,
131 'highthickness' => 4,
132 'quality' => 70,
133 'radius' => 5,
134 'server' => 'osm',
135 'size' => 20,
136 'thickness' => 2,
137 'tz' => 256,
138 'width' => 640,
139 'zoom' => 17
140 ],
141 'prefixes' => [
142 'captcha' => 'captcha',
143 'css' => 'css',
144 'facebook' => 'facebook',
145 'img' => 'img',
146 'map' => 'map',
147 'multi' => 'multi',
148 'pack' => 'pack',
149 'thumb' => 'thumb',
150 'js' => 'js'
151 ],
152 //XXX: use a path relative to __DIR__ as console and index do not have the same execution directory
153 'public' => dirname(__DIR__).'/public',
154 'routes' => [
155 'css' => 'rapsyspack_css',
156 'img' => 'rapsyspack_img',
157 'js' => 'rapsyspack_js'
158 ],
159 'servers' => [
160 'cycle' => 'http://a.tile.thunderforest.com/cycle/{Z}/{X}/{Y}.png',
161 'osm' => 'https://tile.openstreetmap.org/{Z}/{X}/{Y}.png',
162 'transport' => 'http://a.tile.thunderforest.com/transport/{Z}/{X}/{Y}.png'
163 ],
164 'thumb' => [
165 'height' => 128,
166 'width' => 128
167 ],
168 'tokens' => [
169 'css' => 'asset',
170 'img' => 'asset',
171 'js' => 'asset'
172 ]
173 ];
174
175 /**
176 * Defines parameters allowed to configure the bundle
177 *
178 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
179 * @link http://symfony.com/doc/current/components/config/definition.html
180 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
181 *
182 * @see bin/console config:dump-reference rapsyspack to dump default config
183 * @see bin/console debug:config rapsyspack to dump config
184 */
185 $treeBuilder
186 //Parameters
187 ->getRootNode()
188 ->addDefaultsIfNotSet()
189 ->children()
190 ->scalarNode('cache')->cannotBeEmpty()->defaultValue($defaults['cache'])->end()
191 ->arrayNode('captcha')
192 ->addDefaultsIfNotSet()
193 ->children()
194 ->scalarNode('background')->cannotBeEmpty()->defaultValue($defaults['captcha']['background'])->end()
195 ->scalarNode('fill')->cannotBeEmpty()->defaultValue($defaults['captcha']['fill'])->end()
196 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['captcha']['height'])->end()
197 ->scalarNode('size')->cannotBeEmpty()->defaultValue($defaults['captcha']['size'])->end()
198 ->scalarNode('border')->cannotBeEmpty()->defaultValue($defaults['captcha']['border'])->end()
199 ->scalarNode('thickness')->cannotBeEmpty()->defaultValue($defaults['captcha']['thickness'])->end()
200 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['captcha']['width'])->end()
201 ->end()
202 ->end()
203 ->arrayNode('context')
204 ->addDefaultsIfNotSet()
205 ->children()
206 ->arrayNode('http')
207 ->addDefaultsIfNotSet()
208 ->children()
209 ->scalarNode('max_redirects')->defaultValue($defaults['captcha']['max_redirects'])->end()
210 ->scalarNode('timeout')->defaultValue($defaults['captcha']['timeout'])->end()
211 ->scalarNode('user_agent')->cannotBeEmpty()->defaultValue($defaults['captcha']['user_agent'])->end()
212 ->end()
213 ->end()
214 ->end()
215 ->arrayNode('facebook')
216 ->addDefaultsIfNotSet()
217 ->children()
218 ->scalarNode('align')->cannotBeEmpty()->defaultValue($defaults['facebook']['align'])->end()
219 ->scalarNode('fill')->cannotBeEmpty()->defaultValue($defaults['facebook']['fill'])->end()
220 ->scalarNode('font')->cannotBeEmpty()->defaultValue($defaults['facebook']['font'])->end()
221 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['facebook']['height'])->end()
222 ->scalarNode('size')->cannotBeEmpty()->defaultValue($defaults['facebook']['size'])->end()
223 ->scalarNode('source')->cannotBeEmpty()->defaultValue($defaults['facebook']['source'])->end()
224 ->scalarNode('border')->cannotBeEmpty()->defaultValue($defaults['facebook']['border'])->end()
225 ->scalarNode('thickness')->cannotBeEmpty()->defaultValue($defaults['facebook']['thickness'])->end()
226 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['facebook']['width'])->end()
227 ->end()
228 ->end()
229 ->arrayNode('filters')
230 ->addDefaultsIfNotSet()
231 ->children()
232 ->arrayNode('css')
233 /**
234 * Undocumented
235 *
236 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
237 */
238 ->addDefaultChildrenIfNoneSet()
239 ->arrayPrototype()
240 ->children()
241 ->scalarNode('class')
242 ->isRequired()
243 ->cannotBeEmpty()
244 ->defaultValue($defaults['filters']['css'][0]['class'])
245 ->end()
246 ->arrayNode('args')
247 //->isRequired()
248 ->treatNullLike([])
249 ->defaultValue($defaults['filters']['css'][0]['args'])
250 ->scalarPrototype()->end()
251 ->end()
252 ->end()
253 ->end()
254 ->end()
255 ->arrayNode('img')
256 /**
257 * Undocumented
258 *
259 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
260 */
261 ->addDefaultChildrenIfNoneSet()
262 ->arrayPrototype()
263 ->children()
264 ->scalarNode('class')
265 ->isRequired()
266 ->cannotBeEmpty()
267 ->defaultValue($defaults['filters']['img'][0]['class'])
268 ->end()
269 ->arrayNode('args')
270 ->treatNullLike([])
271 ->defaultValue($defaults['filters']['img'][0]['args'])
272 ->scalarPrototype()->end()
273 ->end()
274 ->end()
275 ->end()
276 ->end()
277 ->arrayNode('js')
278 /**
279 * Undocumented
280 *
281 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
282 */
283 ->addDefaultChildrenIfNoneSet()
284 ->arrayPrototype()
285 ->children()
286 ->scalarNode('class')
287 ->isRequired()
288 ->cannotBeEmpty()
289 ->defaultValue($defaults['filters']['js'][0]['class'])
290 ->end()
291 ->arrayNode('args')
292 ->treatNullLike([])
293 ->defaultValue($defaults['filters']['js'][0]['args'])
294 ->scalarPrototype()->end()
295 ->end()
296 ->end()
297 ->end()
298 ->end()
299 ->end()
300 ->end()
301 ->arrayNode('fonts')
302 ->treatNullLike([])
303 ->defaultValue($defaults['fonts'])
304 ->scalarPrototype()->end()
305 ->end()
306 ->arrayNode('map')
307 ->addDefaultsIfNotSet()
308 ->children()
309 ->scalarNode('border')->cannotBeEmpty()->defaultValue($defaults['map']['border'])->end()
310 ->scalarNode('fill')->cannotBeEmpty()->defaultValue($defaults['map']['fill'])->end()
311 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['map']['height'])->end()
312 ->scalarNode('quality')->cannotBeEmpty()->defaultValue($defaults['map']['quality'])->end()
313 ->scalarNode('radius')->cannotBeEmpty()->defaultValue($defaults['map']['radius'])->end()
314 ->scalarNode('server')->cannotBeEmpty()->defaultValue($defaults['map']['server'])->end()
315 ->scalarNode('thickness')->cannotBeEmpty()->defaultValue($defaults['map']['thickness'])->end()
316 ->scalarNode('tz')->cannotBeEmpty()->defaultValue($defaults['map']['tz'])->end()
317 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['map']['width'])->end()
318 ->scalarNode('zoom')->cannotBeEmpty()->defaultValue($defaults['map']['zoom'])->end()
319 ->end()
320 ->end()
321 ->arrayNode('multi')
322 ->addDefaultsIfNotSet()
323 ->children()
324 ->scalarNode('border')->cannotBeEmpty()->defaultValue($defaults['multi']['border'])->end()
325 ->scalarNode('fill')->cannotBeEmpty()->defaultValue($defaults['multi']['fill'])->end()
326 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['multi']['height'])->end()
327 ->scalarNode('highborder')->cannotBeEmpty()->defaultValue($defaults['multi']['highborder'])->end()
328 ->scalarNode('highfill')->cannotBeEmpty()->defaultValue($defaults['multi']['highfill'])->end()
329 ->scalarNode('highradius')->cannotBeEmpty()->defaultValue($defaults['multi']['highradius'])->end()
330 ->scalarNode('highsize')->cannotBeEmpty()->defaultValue($defaults['multi']['highsize'])->end()
331 ->scalarNode('highthickness')->cannotBeEmpty()->defaultValue($defaults['multi']['highthickness'])->end()
332 ->scalarNode('quality')->cannotBeEmpty()->defaultValue($defaults['multi']['quality'])->end()
333 ->scalarNode('radius')->cannotBeEmpty()->defaultValue($defaults['multi']['radius'])->end()
334 ->scalarNode('server')->cannotBeEmpty()->defaultValue($defaults['multi']['server'])->end()
335 ->scalarNode('size')->cannotBeEmpty()->defaultValue($defaults['multi']['size'])->end()
336 ->scalarNode('thickness')->cannotBeEmpty()->defaultValue($defaults['multi']['thickness'])->end()
337 ->scalarNode('tz')->cannotBeEmpty()->defaultValue($defaults['multi']['tz'])->end()
338 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['multi']['width'])->end()
339 ->scalarNode('zoom')->cannotBeEmpty()->defaultValue($defaults['multi']['zoom'])->end()
340 ->end()
341 ->end()
342 ->arrayNode('prefixes')
343 ->treatNullLike([])
344 ->defaultValue($defaults['prefixes'])
345 ->scalarPrototype()->end()
346 ->end()
347 ->scalarNode('public')->cannotBeEmpty()->defaultValue($defaults['public'])->end()
348 ->arrayNode('routes')
349 ->addDefaultsIfNotSet()
350 ->children()
351 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['routes']['css'])->end()
352 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['routes']['img'])->end()
353 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['routes']['js'])->end()
354 ->end()
355 ->end()
356 ->arrayNode('servers')
357 ->treatNullLike([])
358 ->defaultValue($defaults['servers'])
359 ->scalarPrototype()->end()
360 ->end()
361 ->arrayNode('thumb')
362 ->addDefaultsIfNotSet()
363 ->children()
364 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['thumb']['height'])->end()
365 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['thumb']['width'])->end()
366 ->end()
367 ->end()
368 ->arrayNode('tokens')
369 ->addDefaultsIfNotSet()
370 ->children()
371 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['tokens']['css'])->end()
372 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['tokens']['img'])->end()
373 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['tokens']['js'])->end()
374 ->end()
375 ->end()
376 ->end()
377 ->end();
378
379 return $treeBuilder;
380 }
381 }