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\DependencyInjection\Container
;
17 use Symfony\Component\Process\ExecutableFinder
;
19 use Rapsys\PackBundle\RapsysPackBundle
;
22 * This is the class that validates and merges configuration from your app/config files.
24 * @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
42 'name' => 'asset_url',
43 'scheme' => 'https://',
44 'timeout' => (int)ini_get('default_socket_timeout'),
45 'agent' => (string)ini_get('user_agent')?:'rapsys_pack/0.2.0',
49 'css' => '@RapsysPack/css/*.pack.css',
50 'js' => '@RapsysPack/js/*.pack.js',
51 'img' => '@RapsysPack/img/*.pack.jpg'
56 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
58 $finder->find('cpack', '/usr/local/bin/cpack'),
65 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
67 $finder->find('jpack', '/usr/local/bin/jpack'),
74 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
80 'path' => dirname(__DIR__
).'/Resources/public',
81 'url' => '/bundles/'.str_replace('_', '', $alias)
86 * Defines parameters allowed to configure the bundle
88 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
89 * @link http://symfony.com/doc/current/components/config/definition.html
90 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
92 * @see php bin/console config:dump-reference rapsys_pack to dump default config
93 * @see php bin/console debug:config rapsys_pack to dump config
98 ->addDefaultsIfNotSet()
100 ->arrayNode('config')
101 ->addDefaultsIfNotSet()
103 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['config']['name'])->end()
104 ->scalarNode('scheme')->cannotBeEmpty()->defaultValue($defaults['config']['scheme'])->end()
105 ->integerNode('timeout')->min(0)->max(300)->defaultValue($defaults['config']['timeout'])->end()
106 ->scalarNode('agent')->cannotBeEmpty()->defaultValue($defaults['config']['agent'])->end()
107 ->integerNode('redirect')->min(1)->max(30)->defaultValue($defaults['config']['redirect'])->end()
110 ->arrayNode('output')
111 ->addDefaultsIfNotSet()
113 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['output']['css'])->end()
114 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['output']['js'])->end()
115 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['output']['img'])->end()
118 ->arrayNode('filters')
119 ->addDefaultsIfNotSet()
125 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
127 ->addDefaultChildrenIfNoneSet()
130 ->scalarNode('class')
133 ->defaultValue($defaults['filters']['css'][0]['class'])
138 ->defaultValue($defaults['filters']['css'][0]['args'])
139 ->scalarPrototype()->end()
148 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
150 ->addDefaultChildrenIfNoneSet()
153 ->scalarNode('class')
156 ->defaultValue($defaults['filters']['js'][0]['class'])
160 ->defaultValue($defaults['filters']['js'][0]['args'])
161 ->scalarPrototype()->end()
170 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
172 ->addDefaultChildrenIfNoneSet()
175 ->scalarNode('class')
178 ->defaultValue($defaults['filters']['img'][0]['class'])
182 ->defaultValue($defaults['filters']['img'][0]['args'])
183 ->scalarPrototype()->end()
190 ->arrayNode('public')
191 ->addDefaultsIfNotSet()
193 ->scalarNode('path')->cannotBeEmpty()->defaultValue($defaults['public']['path'])->end()
194 ->scalarNode('url')->cannotBeEmpty()->defaultValue($defaults['public']['url'])->end()