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
;
18 use Rapsys\PackBundle\RapsysPackBundle
;
21 * This is the class that validates and merges configuration from your app/config files.
23 * @link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
27 class Configuration
implements ConfigurationInterface
{
31 public function getConfigTreeBuilder(): TreeBuilder
{
32 //Get TreeBuilder object
33 $treeBuilder = new TreeBuilder(RapsysPackBundle
::getAlias());
35 //Get ExecutableFinder object
36 $finder = new ExecutableFinder();
38 //The bundle default values
41 'name' => 'asset_url',
42 'scheme' => 'https://',
43 'timeout' => (int)ini_get('default_socket_timeout'),
44 'agent' => (string)ini_get('user_agent')?:'rapsys_pack/0.2.0',
48 'css' => '@RapsysPack/css/*.pack.css',
49 'js' => '@RapsysPack/js/*.pack.js',
50 'img' => '@RapsysPack/img/*.pack.jpg'
55 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
57 $finder->find('cpack', '/usr/local/bin/cpack'),
64 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
66 $finder->find('jpack', '/usr/local/bin/jpack'),
73 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
81 * Defines parameters allowed to configure the bundle
83 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
84 * @link http://symfony.com/doc/current/components/config/definition.html
85 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
87 * @see php bin/console config:dump-reference rapsys_pack to dump default config
88 * @see php bin/console debug:config rapsys_pack to dump config
93 ->addDefaultsIfNotSet()
96 ->addDefaultsIfNotSet()
98 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['config']['name'])->end()
99 ->scalarNode('scheme')->cannotBeEmpty()->defaultValue($defaults['config']['scheme'])->end()
100 ->integerNode('timeout')->min(0)->max(300)->defaultValue($defaults['config']['timeout'])->end()
101 ->scalarNode('agent')->cannotBeEmpty()->defaultValue($defaults['config']['agent'])->end()
102 ->integerNode('redirect')->min(1)->max(30)->defaultValue($defaults['config']['redirect'])->end()
105 ->arrayNode('output')
106 ->addDefaultsIfNotSet()
108 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['output']['css'])->end()
109 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['output']['js'])->end()
110 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['output']['img'])->end()
113 ->arrayNode('filters')
114 ->addDefaultsIfNotSet()
120 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
122 ->addDefaultChildrenIfNoneSet()
125 ->scalarNode('class')
128 ->defaultValue($defaults['filters']['css'][0]['class'])
133 ->defaultValue($defaults['filters']['css'][0]['args'])
134 ->scalarPrototype()->end()
143 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
145 ->addDefaultChildrenIfNoneSet()
148 ->scalarNode('class')
151 ->defaultValue($defaults['filters']['js'][0]['class'])
155 ->defaultValue($defaults['filters']['js'][0]['args'])
156 ->scalarPrototype()->end()
165 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
167 ->addDefaultChildrenIfNoneSet()
170 ->scalarNode('class')
173 ->defaultValue($defaults['filters']['img'][0]['class'])
177 ->defaultValue($defaults['filters']['img'][0]['args'])
178 ->scalarPrototype()->end()