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.2',
48 #TODO: migrate to public.path, public.url and router->generateUrl ?
49 #XXX: that would means dropping the PathPackage stuff and use static route like rapsys_pack_facebook
51 'css' => '@RapsysPack/css/*.pack.css',
52 'js' => '@RapsysPack/js/*.pack.js',
53 'img' => '@RapsysPack/img/*.pack.jpg'
58 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
60 $finder->find('cpack', '/usr/local/bin/cpack'),
67 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
69 $finder->find('jpack', '/usr/local/bin/jpack'),
76 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
81 'path' => dirname(__DIR__
).'/Resources/public',
85 * Defines parameters allowed to configure the bundle
87 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
88 * @link http://symfony.com/doc/current/components/config/definition.html
89 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
91 * @see php bin/console config:dump-reference rapsys_pack to dump default config
92 * @see php bin/console debug:config rapsys_pack to dump config
97 ->addDefaultsIfNotSet()
100 ->addDefaultsIfNotSet()
102 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['config']['name'])->end()
103 ->scalarNode('scheme')->cannotBeEmpty()->defaultValue($defaults['config']['scheme'])->end()
104 ->integerNode('timeout')->min(0)->max(300)->defaultValue($defaults['config']['timeout'])->end()
105 ->scalarNode('agent')->cannotBeEmpty()->defaultValue($defaults['config']['agent'])->end()
106 ->integerNode('redirect')->min(1)->max(30)->defaultValue($defaults['config']['redirect'])->end()
109 ->arrayNode('output')
110 ->addDefaultsIfNotSet()
112 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['output']['css'])->end()
113 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['output']['js'])->end()
114 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['output']['img'])->end()
117 ->arrayNode('filters')
118 ->addDefaultsIfNotSet()
124 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
126 ->addDefaultChildrenIfNoneSet()
129 ->scalarNode('class')
132 ->defaultValue($defaults['filters']['css'][0]['class'])
137 ->defaultValue($defaults['filters']['css'][0]['args'])
138 ->scalarPrototype()->end()
147 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
149 ->addDefaultChildrenIfNoneSet()
152 ->scalarNode('class')
155 ->defaultValue($defaults['filters']['js'][0]['class'])
159 ->defaultValue($defaults['filters']['js'][0]['args'])
160 ->scalarPrototype()->end()
169 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
171 ->addDefaultChildrenIfNoneSet()
174 ->scalarNode('class')
177 ->defaultValue($defaults['filters']['img'][0]['class'])
181 ->defaultValue($defaults['filters']['img'][0]['args'])
182 ->scalarPrototype()->end()
189 ->scalarNode('path')->cannotBeEmpty()->defaultValue($defaults['path'])->end()