]> Raphaël G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
Add cleanup ideas for packer
[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 #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
50 'output' => [
51 'css' => '@RapsysPack/css/*.pack.css',
52 'js' => '@RapsysPack/js/*.pack.js',
53 'img' => '@RapsysPack/img/*.pack.jpg'
54 ],
55 'filters' => [
56 'css' => [
57 0 => [
58 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
59 'args' => [
60 $finder->find('cpack', '/usr/local/bin/cpack'),
61 'minify'
62 ]
63 ]
64 ],
65 'js' => [
66 0 => [
67 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
68 'args' => [
69 $finder->find('jpack', '/usr/local/bin/jpack'),
70 'best'
71 ]
72 ]
73 ],
74 'img' => [
75 0 => [
76 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
77 'args' => []
78 ]
79 ],
80 ],
81 'public' => [
82 'path' => dirname(__DIR__).'/Resources/public',
83 'url' => '/bundles/'.str_replace('_', '', $alias)
84 ]
85 ];
86
87 /**
88 * Defines parameters allowed to configure the bundle
89 *
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
93 *
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
96 */
97 $treeBuilder
98 //Parameters
99 ->getRootNode()
100 ->addDefaultsIfNotSet()
101 ->children()
102 ->arrayNode('config')
103 ->addDefaultsIfNotSet()
104 ->children()
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()
110 ->end()
111 ->end()
112 ->arrayNode('output')
113 ->addDefaultsIfNotSet()
114 ->children()
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()
118 ->end()
119 ->end()
120 ->arrayNode('filters')
121 ->addDefaultsIfNotSet()
122 ->children()
123 ->arrayNode('css')
124 /**
125 * Undocumented
126 *
127 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
128 */
129 ->addDefaultChildrenIfNoneSet()
130 ->arrayPrototype()
131 ->children()
132 ->scalarNode('class')
133 ->isRequired()
134 ->cannotBeEmpty()
135 ->defaultValue($defaults['filters']['css'][0]['class'])
136 ->end()
137 ->arrayNode('args')
138 //->isRequired()
139 ->treatNullLike([])
140 ->defaultValue($defaults['filters']['css'][0]['args'])
141 ->scalarPrototype()->end()
142 ->end()
143 ->end()
144 ->end()
145 ->end()
146 ->arrayNode('js')
147 /**
148 * Undocumented
149 *
150 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
151 */
152 ->addDefaultChildrenIfNoneSet()
153 ->arrayPrototype()
154 ->children()
155 ->scalarNode('class')
156 ->isRequired()
157 ->cannotBeEmpty()
158 ->defaultValue($defaults['filters']['js'][0]['class'])
159 ->end()
160 ->arrayNode('args')
161 ->treatNullLike([])
162 ->defaultValue($defaults['filters']['js'][0]['args'])
163 ->scalarPrototype()->end()
164 ->end()
165 ->end()
166 ->end()
167 ->end()
168 ->arrayNode('img')
169 /**
170 * Undocumented
171 *
172 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
173 */
174 ->addDefaultChildrenIfNoneSet()
175 ->arrayPrototype()
176 ->children()
177 ->scalarNode('class')
178 ->isRequired()
179 ->cannotBeEmpty()
180 ->defaultValue($defaults['filters']['img'][0]['class'])
181 ->end()
182 ->arrayNode('args')
183 ->treatNullLike([])
184 ->defaultValue($defaults['filters']['img'][0]['args'])
185 ->scalarPrototype()->end()
186 ->end()
187 ->end()
188 ->end()
189 ->end()
190 ->end()
191 ->end()
192 ->arrayNode('public')
193 ->addDefaultsIfNotSet()
194 ->children()
195 ->scalarNode('path')->cannotBeEmpty()->defaultValue($defaults['public']['path'])->end()
196 ->scalarNode('url')->cannotBeEmpty()->defaultValue($defaults['public']['url'])->end()
197 ->end()
198 ->end()
199 ->end()
200 ->end();
201
202 return $treeBuilder;
203 }
204 }