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',
49 'border' => '#00c3f9',
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()))
66 'source' => dirname(__DIR__
).'/public/facebook/source.png',
67 'border' => '#00c3f9',
74 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
76 $finder->find('cpack', '/usr/local/bin/cpack'),
83 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
89 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
91 $finder->find('jpack', '/usr/local/bin/jpack'),
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'
112 'border' => '#00c3f9',
124 'border' => '#00c3f9',
127 'highborder' => '#3333c3',
128 'highfill' => '#c3c3f9',
131 'highthickness' => 4,
142 'captcha' => 'captcha',
144 'facebook' => 'facebook',
152 //XXX: use a path relative to __DIR__ as console and index do not have the same execution directory
153 'public' => dirname(__DIR__
).'/public',
155 'css' => 'rapsyspack_css',
156 'img' => 'rapsyspack_img',
157 'js' => 'rapsyspack_js'
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'
176 * Defines parameters allowed to configure the bundle
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
182 * @see bin/console config:dump-reference rapsyspack to dump default config
183 * @see bin/console debug:config rapsyspack to dump config
188 ->addDefaultsIfNotSet()
190 ->scalarNode('cache')->cannotBeEmpty()->defaultValue($defaults['cache'])->end()
191 ->arrayNode('captcha')
192 ->addDefaultsIfNotSet()
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()
203 ->arrayNode('context')
204 ->addDefaultsIfNotSet()
207 ->addDefaultsIfNotSet()
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()
215 ->arrayNode('facebook')
216 ->addDefaultsIfNotSet()
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()
229 ->arrayNode('filters')
230 ->addDefaultsIfNotSet()
236 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
238 ->addDefaultChildrenIfNoneSet()
241 ->scalarNode('class')
244 ->defaultValue($defaults['filters']['css'][0]['class'])
249 ->defaultValue($defaults['filters']['css'][0]['args'])
250 ->scalarPrototype()->end()
259 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
261 ->addDefaultChildrenIfNoneSet()
264 ->scalarNode('class')
267 ->defaultValue($defaults['filters']['img'][0]['class'])
271 ->defaultValue($defaults['filters']['img'][0]['args'])
272 ->scalarPrototype()->end()
281 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
283 ->addDefaultChildrenIfNoneSet()
286 ->scalarNode('class')
289 ->defaultValue($defaults['filters']['js'][0]['class'])
293 ->defaultValue($defaults['filters']['js'][0]['args'])
294 ->scalarPrototype()->end()
303 ->defaultValue($defaults['fonts'])
304 ->scalarPrototype()->end()
307 ->addDefaultsIfNotSet()
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()
322 ->addDefaultsIfNotSet()
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()
342 ->arrayNode('prefixes')
344 ->defaultValue($defaults['prefixes'])
345 ->scalarPrototype()->end()
347 ->scalarNode('public')->cannotBeEmpty()->defaultValue($defaults['public'])->end()
348 ->arrayNode('routes')
349 ->addDefaultsIfNotSet()
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()
356 ->arrayNode('servers')
358 ->defaultValue($defaults['servers'])
359 ->scalarPrototype()->end()
362 ->addDefaultsIfNotSet()
364 ->scalarNode('height')->cannotBeEmpty()->defaultValue($defaults['thumb']['height'])->end()
365 ->scalarNode('width')->cannotBeEmpty()->defaultValue($defaults['thumb']['width'])->end()
368 ->arrayNode('tokens')
369 ->addDefaultsIfNotSet()
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()