]> Raphaël G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
Add rapsys_pack.facebook_util and rapsys_pack.image_util services
[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.1',
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 'path' => dirname(__DIR__).'/Resources/public',
82 ];
83
84 /**
85 * Defines parameters allowed to configure the bundle
86 *
87 * @link https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
88 * @link http://symfony.com/doc/current/components/config/definition.html
89 * @link https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
90 *
91 * @see php bin/console config:dump-reference rapsys_pack to dump default config
92 * @see php bin/console debug:config rapsys_pack to dump config
93 */
94 $treeBuilder
95 //Parameters
96 ->getRootNode()
97 ->addDefaultsIfNotSet()
98 ->children()
99 ->arrayNode('config')
100 ->addDefaultsIfNotSet()
101 ->children()
102 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['config']['name'])->end()
103 ->scalarNode('scheme')->cannotBeEmpty()->defaultValue($defaults['config']['scheme'])->end()
104 ->integerNode('timeout')->min(0)->max(300)->defaultValue($defaults['config']['timeout'])->end()
105 ->scalarNode('agent')->cannotBeEmpty()->defaultValue($defaults['config']['agent'])->end()
106 ->integerNode('redirect')->min(1)->max(30)->defaultValue($defaults['config']['redirect'])->end()
107 ->end()
108 ->end()
109 ->arrayNode('output')
110 ->addDefaultsIfNotSet()
111 ->children()
112 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['output']['css'])->end()
113 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['output']['js'])->end()
114 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['output']['img'])->end()
115 ->end()
116 ->end()
117 ->arrayNode('filters')
118 ->addDefaultsIfNotSet()
119 ->children()
120 ->arrayNode('css')
121 /**
122 * Undocumented
123 *
124 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
125 */
126 ->addDefaultChildrenIfNoneSet()
127 ->arrayPrototype()
128 ->children()
129 ->scalarNode('class')
130 ->isRequired()
131 ->cannotBeEmpty()
132 ->defaultValue($defaults['filters']['css'][0]['class'])
133 ->end()
134 ->arrayNode('args')
135 //->isRequired()
136 ->treatNullLike([])
137 ->defaultValue($defaults['filters']['css'][0]['args'])
138 ->scalarPrototype()->end()
139 ->end()
140 ->end()
141 ->end()
142 ->end()
143 ->arrayNode('js')
144 /**
145 * Undocumented
146 *
147 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
148 */
149 ->addDefaultChildrenIfNoneSet()
150 ->arrayPrototype()
151 ->children()
152 ->scalarNode('class')
153 ->isRequired()
154 ->cannotBeEmpty()
155 ->defaultValue($defaults['filters']['js'][0]['class'])
156 ->end()
157 ->arrayNode('args')
158 ->treatNullLike([])
159 ->defaultValue($defaults['filters']['js'][0]['args'])
160 ->scalarPrototype()->end()
161 ->end()
162 ->end()
163 ->end()
164 ->end()
165 ->arrayNode('img')
166 /**
167 * Undocumented
168 *
169 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
170 */
171 ->addDefaultChildrenIfNoneSet()
172 ->arrayPrototype()
173 ->children()
174 ->scalarNode('class')
175 ->isRequired()
176 ->cannotBeEmpty()
177 ->defaultValue($defaults['filters']['img'][0]['class'])
178 ->end()
179 ->arrayNode('args')
180 ->treatNullLike([])
181 ->defaultValue($defaults['filters']['img'][0]['args'])
182 ->scalarPrototype()->end()
183 ->end()
184 ->end()
185 ->end()
186 ->end()
187 ->end()
188 ->end()
189 ->scalarNode('path')->cannotBeEmpty()->defaultValue($defaults['path'])->end()
190 ->end()
191 ->end();
192
193 return $treeBuilder;
194 }
195 }