]> Raphaël G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
Cleanup
[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 use Rapsys\PackBundle\RapsysPackBundle;
19
20 /**
21 * This is the class that validates and merges configuration from your app/config files.
22 *
23 * @link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
24 *
25 * {@inheritdoc}
26 */
27 class Configuration implements ConfigurationInterface {
28 /**
29 * {@inheritdoc}
30 */
31 public function getConfigTreeBuilder(): TreeBuilder {
32 //Get TreeBuilder object
33 $treeBuilder = new TreeBuilder(RapsysPackBundle::getAlias());
34
35 //Get ExecutableFinder object
36 $finder = new ExecutableFinder();
37
38 //The bundle default values
39 $defaults = [
40 'config' => [
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',
45 'redirect' => 5
46 ],
47 'output' => [
48 'css' => '@RapsysPack/css/*.pack.css',
49 'js' => '@RapsysPack/js/*.pack.js',
50 'img' => '@RapsysPack/img/*.pack.jpg'
51 ],
52 'filters' => [
53 'css' => [
54 0 => [
55 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
56 'args' => [
57 $finder->find('cpack', '/usr/local/bin/cpack'),
58 'minify'
59 ]
60 ]
61 ],
62 'js' => [
63 0 => [
64 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
65 'args' => [
66 $finder->find('jpack', '/usr/local/bin/jpack'),
67 'best'
68 ]
69 ]
70 ],
71 'img' => [
72 0 => [
73 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
74 'args' => []
75 ]
76 ],
77 ]
78 ];
79
80 /**
81 * Defines parameters allowed to configure the bundle
82 *
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
86 *
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
89 */
90 $treeBuilder
91 //Parameters
92 ->getRootNode()
93 ->addDefaultsIfNotSet()
94 ->children()
95 ->arrayNode('config')
96 ->addDefaultsIfNotSet()
97 ->children()
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()
103 ->end()
104 ->end()
105 ->arrayNode('output')
106 ->addDefaultsIfNotSet()
107 ->children()
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()
111 ->end()
112 ->end()
113 ->arrayNode('filters')
114 ->addDefaultsIfNotSet()
115 ->children()
116 ->arrayNode('css')
117 /**
118 * Undocumented
119 *
120 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
121 */
122 ->addDefaultChildrenIfNoneSet()
123 ->arrayPrototype()
124 ->children()
125 ->scalarNode('class')
126 ->isRequired()
127 ->cannotBeEmpty()
128 ->defaultValue($defaults['filters']['css'][0]['class'])
129 ->end()
130 ->arrayNode('args')
131 //->isRequired()
132 ->treatNullLike([])
133 ->defaultValue($defaults['filters']['css'][0]['args'])
134 ->scalarPrototype()->end()
135 ->end()
136 ->end()
137 ->end()
138 ->end()
139 ->arrayNode('js')
140 /**
141 * Undocumented
142 *
143 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
144 */
145 ->addDefaultChildrenIfNoneSet()
146 ->arrayPrototype()
147 ->children()
148 ->scalarNode('class')
149 ->isRequired()
150 ->cannotBeEmpty()
151 ->defaultValue($defaults['filters']['js'][0]['class'])
152 ->end()
153 ->arrayNode('args')
154 ->treatNullLike([])
155 ->defaultValue($defaults['filters']['js'][0]['args'])
156 ->scalarPrototype()->end()
157 ->end()
158 ->end()
159 ->end()
160 ->end()
161 ->arrayNode('img')
162 /**
163 * Undocumented
164 *
165 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
166 */
167 ->addDefaultChildrenIfNoneSet()
168 ->arrayPrototype()
169 ->children()
170 ->scalarNode('class')
171 ->isRequired()
172 ->cannotBeEmpty()
173 ->defaultValue($defaults['filters']['img'][0]['class'])
174 ->end()
175 ->arrayNode('args')
176 ->treatNullLike([])
177 ->defaultValue($defaults['filters']['img'][0]['args'])
178 ->scalarPrototype()->end()
179 ->end()
180 ->end()
181 ->end()
182 ->end()
183 ->end()
184 ->end()
185 ->end()
186 ->end();
187
188 return $treeBuilder;
189 }
190 }