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