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 Symfony\Component\Config\Definition\Builder\TreeBuilder
;
15 use Symfony\Component\Config\Definition\ConfigurationInterface
;
16 use Symfony\Component\Process\ExecutableFinder
;
19 * This is the class that validates and merges configuration from your app/config files.
21 * @link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
25 class Configuration
implements ConfigurationInterface
{
29 public function getConfigTreeBuilder(): TreeBuilder
{
30 //Get TreeBuilder object
31 $treeBuilder = new TreeBuilder('rapsys_pack');
33 //Get ExecutableFinder object
34 $finder = new ExecutableFinder();
36 //The bundle default values
39 'name' => 'asset_url',
40 'scheme' => 'https://',
41 'timeout' => (int)ini_get('default_socket_timeout'),
42 'agent' => (string)ini_get('user_agent')?:'rapsys_pack/0.2.0',
46 'css' => '@RapsysPack/css/*.pack.css',
47 'js' => '@RapsysPack/js/*.pack.js',
48 'img' => '@RapsysPack/img/*.pack.jpg'
53 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
55 $finder->find('cpack', '/usr/local/bin/cpack'),
62 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
64 $finder->find('jpack', '/usr/local/bin/jpack'),
71 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
79 * Defines parameters allowed to configure the bundle
81 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
82 * @link http://symfony.com/doc/current/components/config/definition.html
83 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
85 * @see php bin/console config:dump-reference rapsys_pack to dump default config
86 * @see php bin/console debug:config rapsys_pack to dump config
91 ->addDefaultsIfNotSet()
94 ->addDefaultsIfNotSet()
96 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['config']['name'])->end()
97 ->scalarNode('scheme')->cannotBeEmpty()->defaultValue($defaults['config']['scheme'])->end()
98 ->integerNode('timeout')->min(0)->max(300)->defaultValue($defaults['config']['timeout'])->end()
99 ->scalarNode('agent')->cannotBeEmpty()->defaultValue($defaults['config']['agent'])->end()
100 ->integerNode('redirect')->min(1)->max(30)->defaultValue($defaults['config']['redirect'])->end()
103 ->arrayNode('output')
104 ->addDefaultsIfNotSet()
106 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['output']['css'])->end()
107 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['output']['js'])->end()
108 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['output']['img'])->end()
111 ->arrayNode('filters')
112 ->addDefaultsIfNotSet()
118 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
120 ->addDefaultChildrenIfNoneSet()
123 ->scalarNode('class')
126 ->defaultValue($defaults['filters']['css'][0]['class'])
131 ->defaultValue($defaults['filters']['css'][0]['args'])
132 ->scalarPrototype()->end()
141 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
143 ->addDefaultChildrenIfNoneSet()
146 ->scalarNode('class')
149 ->defaultValue($defaults['filters']['js'][0]['class'])
153 ->defaultValue($defaults['filters']['js'][0]['args'])
154 ->scalarPrototype()->end()
163 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
165 ->addDefaultChildrenIfNoneSet()
168 ->scalarNode('class')
171 ->defaultValue($defaults['filters']['img'][0]['class'])
175 ->defaultValue($defaults['filters']['img'][0]['args'])
176 ->scalarPrototype()->end()