1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys PackBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\PackBundle\DependencyInjection
;
14 use Rapsys\PackBundle\RapsysPackBundle
;
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
;
24 * This is the class that validates and merges configuration from your app/config files.
26 * @link http://symfony.com/doc/current/cookbook/bundles/configuration.html
28 class Configuration
implements ConfigurationInterface
{
32 public function getConfigTreeBuilder(): TreeBuilder
{
33 //Get TreeBuilder object
34 $treeBuilder = new TreeBuilder($alias = RapsysPackBundle
::getAlias());
36 //Get ExecutableFinder object
37 $finder = new ExecutableFinder();
39 //The bundle default values
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,
45 'background' => 'white',
50 'border' => '#00c3f9',
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()))
68 'source' => dirname(__DIR__
).'/public/facebook/source.png',
69 'border' => '#00c3f9',
76 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
78 $finder->find('cpack', '/usr/local/bin/cpack'),
85 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
91 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
93 $finder->find('jpack', '/usr/local/bin/jpack'),
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'
114 'border' => '#00c3f9',
127 'border' => '#00c3f9',
131 'highborder' => '#3333c3',
132 'highfill' => '#c3c3f9',
135 'highthickness' => 4,
146 'captcha' => 'captcha',
148 'facebook' => 'facebook',
156 //XXX: use a path relative to __DIR__ as console and index do not have the same execution directory
157 'public' => dirname(__DIR__
).'/public',
159 'css' => 'rapsyspack_css',
160 'img' => 'rapsyspack_img',
161 'js' => 'rapsyspack_js'
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'
180 * Defines parameters allowed to configure the bundle
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
186 * @see bin/console config:dump-reference rapsyspack to dump default config
187 * @see bin/console debug:config rapsyspack to dump config
192 ->addDefaultsIfNotSet()
194 ->scalarNode('cache')->cannotBeEmpty()->defaultValue($defaults['cache'])->end()
195 ->arrayNode('captcha')
196 ->addDefaultsIfNotSet()
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()
208 ->arrayNode('context')
209 ->addDefaultsIfNotSet()
212 ->addDefaultsIfNotSet()
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()
221 ->arrayNode('facebook')
222 ->addDefaultsIfNotSet()
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()
236 ->arrayNode('filters')
237 ->addDefaultsIfNotSet()
243 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
245 ->addDefaultChildrenIfNoneSet()
248 ->scalarNode('class')
251 ->defaultValue($defaults['filters']['css'][0]['class'])
256 ->defaultValue($defaults['filters']['css'][0]['args'])
257 ->scalarPrototype()->end()
266 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
268 ->addDefaultChildrenIfNoneSet()
271 ->scalarNode('class')
274 ->defaultValue($defaults['filters']['img'][0]['class'])
278 ->defaultValue($defaults['filters']['img'][0]['args'])
279 ->scalarPrototype()->end()
288 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
290 ->addDefaultChildrenIfNoneSet()
293 ->scalarNode('class')
296 ->defaultValue($defaults['filters']['js'][0]['class'])
300 ->defaultValue($defaults['filters']['js'][0]['args'])
301 ->scalarPrototype()->end()
310 ->defaultValue($defaults['fonts'])
311 ->scalarPrototype()->end()
314 ->addDefaultsIfNotSet()
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()
330 ->addDefaultsIfNotSet()
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()
351 ->arrayNode('prefixes')
353 ->defaultValue($defaults['prefixes'])
354 ->scalarPrototype()->end()
356 ->scalarNode('public')->cannotBeEmpty()->defaultValue($defaults['public'])->end()
357 ->arrayNode('routes')
358 ->addDefaultsIfNotSet()
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()
365 ->arrayNode('servers')
367 ->defaultValue($defaults['servers'])
368 ->scalarPrototype()->end()
371 ->addDefaultsIfNotSet()
373 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['thumb']['height'])->end()
374 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['thumb']['width'])->end()
377 ->arrayNode('tokens')
378 ->addDefaultsIfNotSet()
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()