]> Raphaël G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
Add hash, short and unshort twig filter
[packbundle] / DependencyInjection / Configuration.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys PackBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\PackBundle\DependencyInjection;
13
14 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15 use Symfony\Component\Config\Definition\ConfigurationInterface;
16 use Symfony\Component\Process\ExecutableFinder;
17
18 /**
19 * This is the class that validates and merges configuration from your app/config files.
20 *
21 * @link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
22 *
23 * {@inheritdoc}
24 */
25 class Configuration implements ConfigurationInterface {
26 /**
27 * {@inheritdoc}
28 */
29 public function getConfigTreeBuilder(): TreeBuilder {
30 //Get TreeBuilder object
31 $treeBuilder = new TreeBuilder('rapsys_pack');
32
33 //Get ExecutableFinder object
34 $finder = new ExecutableFinder();
35
36 //The bundle default values
37 $defaults = [
38 'config' => [
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',
43 'redirect' => 5
44 ],
45 'output' => [
46 'css' => '@RapsysPack/css/*.pack.css',
47 'js' => '@RapsysPack/js/*.pack.js',
48 'img' => '@RapsysPack/img/*.pack.jpg'
49 ],
50 'filters' => [
51 'css' => [
52 0 => [
53 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
54 'args' => [
55 $finder->find('cpack', '/usr/local/bin/cpack'),
56 'minify'
57 ]
58 ]
59 ],
60 'js' => [
61 0 => [
62 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
63 'args' => [
64 $finder->find('jpack', '/usr/local/bin/jpack'),
65 'best'
66 ]
67 ]
68 ],
69 'img' => [
70 0 => [
71 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
72 'args' => []
73 ]
74 ],
75 ]
76 ];
77
78 /**
79 * Defines parameters allowed to configure the bundle
80 *
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
84 *
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
87 */
88 $treeBuilder
89 //Parameters
90 ->getRootNode()
91 ->addDefaultsIfNotSet()
92 ->children()
93 ->arrayNode('config')
94 ->addDefaultsIfNotSet()
95 ->children()
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()
101 ->end()
102 ->end()
103 ->arrayNode('output')
104 ->addDefaultsIfNotSet()
105 ->children()
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()
109 ->end()
110 ->end()
111 ->arrayNode('filters')
112 ->addDefaultsIfNotSet()
113 ->children()
114 ->arrayNode('css')
115 /**
116 * Undocumented
117 *
118 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
119 */
120 ->addDefaultChildrenIfNoneSet()
121 ->arrayPrototype()
122 ->children()
123 ->scalarNode('class')
124 ->isRequired()
125 ->cannotBeEmpty()
126 ->defaultValue($defaults['filters']['css'][0]['class'])
127 ->end()
128 ->arrayNode('args')
129 //->isRequired()
130 ->treatNullLike([])
131 ->defaultValue($defaults['filters']['css'][0]['args'])
132 ->scalarPrototype()->end()
133 ->end()
134 ->end()
135 ->end()
136 ->end()
137 ->arrayNode('js')
138 /**
139 * Undocumented
140 *
141 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
142 */
143 ->addDefaultChildrenIfNoneSet()
144 ->arrayPrototype()
145 ->children()
146 ->scalarNode('class')
147 ->isRequired()
148 ->cannotBeEmpty()
149 ->defaultValue($defaults['filters']['js'][0]['class'])
150 ->end()
151 ->arrayNode('args')
152 ->treatNullLike([])
153 ->defaultValue($defaults['filters']['js'][0]['args'])
154 ->scalarPrototype()->end()
155 ->end()
156 ->end()
157 ->end()
158 ->end()
159 ->arrayNode('img')
160 /**
161 * Undocumented
162 *
163 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
164 */
165 ->addDefaultChildrenIfNoneSet()
166 ->arrayPrototype()
167 ->children()
168 ->scalarNode('class')
169 ->isRequired()
170 ->cannotBeEmpty()
171 ->defaultValue($defaults['filters']['img'][0]['class'])
172 ->end()
173 ->arrayNode('args')
174 ->treatNullLike([])
175 ->defaultValue($defaults['filters']['img'][0]['args'])
176 ->scalarPrototype()->end()
177 ->end()
178 ->end()
179 ->end()
180 ->end()
181 ->end()
182 ->end()
183 ->end()
184 ->end();
185
186 return $treeBuilder;
187 }
188 }