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