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',
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',
82 'path' => dirname(__DIR__
).'/Resources/public',
83 'url' => '/bundles/'.str_replace('_', '', $alias)
88 * Defines parameters allowed to configure the bundle
90 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
91 * @link http://symfony.com/doc/current/components/config/definition.html
92 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
94 * @see php bin/console config:dump-reference rapsys_pack to dump default config
95 * @see php bin/console debug:config rapsys_pack to dump config
100 ->addDefaultsIfNotSet()
102 ->arrayNode('config')
103 ->addDefaultsIfNotSet()
105 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['config']['name'])->end()
106 ->scalarNode('scheme')->cannotBeEmpty()->defaultValue($defaults['config']['scheme'])->end()
107 ->integerNode('timeout')->min(0)->max(300)->defaultValue($defaults['config']['timeout'])->end()
108 ->scalarNode('agent')->cannotBeEmpty()->defaultValue($defaults['config']['agent'])->end()
109 ->integerNode('redirect')->min(1)->max(30)->defaultValue($defaults['config']['redirect'])->end()
112 ->arrayNode('output')
113 ->addDefaultsIfNotSet()
115 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['output']['css'])->end()
116 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['output']['js'])->end()
117 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['output']['img'])->end()
120 ->arrayNode('filters')
121 ->addDefaultsIfNotSet()
127 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
129 ->addDefaultChildrenIfNoneSet()
132 ->scalarNode('class')
135 ->defaultValue($defaults['filters']['css'][0]['class'])
140 ->defaultValue($defaults['filters']['css'][0]['args'])
141 ->scalarPrototype()->end()
150 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
152 ->addDefaultChildrenIfNoneSet()
155 ->scalarNode('class')
158 ->defaultValue($defaults['filters']['js'][0]['class'])
162 ->defaultValue($defaults['filters']['js'][0]['args'])
163 ->scalarPrototype()->end()
172 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
174 ->addDefaultChildrenIfNoneSet()
177 ->scalarNode('class')
180 ->defaultValue($defaults['filters']['img'][0]['class'])
184 ->defaultValue($defaults['filters']['img'][0]['args'])
185 ->scalarPrototype()->end()
192 ->arrayNode('public')
193 ->addDefaultsIfNotSet()
195 ->scalarNode('path')->cannotBeEmpty()->defaultValue($defaults['public']['path'])->end()
196 ->scalarNode('url')->cannotBeEmpty()->defaultValue($defaults['public']['url'])->end()