]> Raphaël G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
Replace filters, output and token with parameters argument
[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 'filters' => [
42 'css' => [
43 0 => [
44 'class' => 'Rapsys\PackBundle\Filter\CPackFilter',
45 'args' => [
46 $finder->find('cpack', '/usr/local/bin/cpack'),
47 'minify'
48 ]
49 ]
50 ],
51 'img' => [
52 0 => [
53 'class' => 'Rapsys\PackBundle\Filter\IPackFilter',
54 'args' => []
55 ]
56 ],
57 'js' => [
58 0 => [
59 'class' => 'Rapsys\PackBundle\Filter\JPackFilter',
60 'args' => [
61 $finder->find('jpack', '/usr/local/bin/jpack'),
62 'best'
63 ]
64 ]
65 ]
66 ],
67 #TODO: migrate to public.path, public.url and router->generateUrl ?
68 #XXX: that would means dropping the PathPackage stuff and use static route like rapsys_pack_facebook
69 'output' => [
70 'css' => '@RapsysPack/css/*.pack.css',
71 'img' => '@RapsysPack/img/*.pack.jpg',
72 'js' => '@RapsysPack/js/*.pack.js'
73 ],
74 'path' => dirname(__DIR__).'/Resources/public',
75 'token' => 'asset_url'
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('filters')
94 ->addDefaultsIfNotSet()
95 ->children()
96 ->arrayNode('css')
97 /**
98 * Undocumented
99 *
100 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
101 */
102 ->addDefaultChildrenIfNoneSet()
103 ->arrayPrototype()
104 ->children()
105 ->scalarNode('class')
106 ->isRequired()
107 ->cannotBeEmpty()
108 ->defaultValue($defaults['filters']['css'][0]['class'])
109 ->end()
110 ->arrayNode('args')
111 //->isRequired()
112 ->treatNullLike([])
113 ->defaultValue($defaults['filters']['css'][0]['args'])
114 ->scalarPrototype()->end()
115 ->end()
116 ->end()
117 ->end()
118 ->end()
119 ->arrayNode('img')
120 /**
121 * Undocumented
122 *
123 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
124 */
125 ->addDefaultChildrenIfNoneSet()
126 ->arrayPrototype()
127 ->children()
128 ->scalarNode('class')
129 ->isRequired()
130 ->cannotBeEmpty()
131 ->defaultValue($defaults['filters']['img'][0]['class'])
132 ->end()
133 ->arrayNode('args')
134 ->treatNullLike([])
135 ->defaultValue($defaults['filters']['img'][0]['args'])
136 ->scalarPrototype()->end()
137 ->end()
138 ->end()
139 ->end()
140 ->end()
141 ->arrayNode('js')
142 /**
143 * Undocumented
144 *
145 * @see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
146 */
147 ->addDefaultChildrenIfNoneSet()
148 ->arrayPrototype()
149 ->children()
150 ->scalarNode('class')
151 ->isRequired()
152 ->cannotBeEmpty()
153 ->defaultValue($defaults['filters']['js'][0]['class'])
154 ->end()
155 ->arrayNode('args')
156 ->treatNullLike([])
157 ->defaultValue($defaults['filters']['js'][0]['args'])
158 ->scalarPrototype()->end()
159 ->end()
160 ->end()
161 ->end()
162 ->end()
163 ->end()
164 ->end()
165 ->arrayNode('output')
166 ->addDefaultsIfNotSet()
167 ->children()
168 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['output']['css'])->end()
169 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['output']['img'])->end()
170 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['output']['js'])->end()
171 ->end()
172 ->end()
173 ->scalarNode('path')->cannotBeEmpty()->defaultValue($defaults['path'])->end()
174 ->scalarNode('token')->cannotBeEmpty()->defaultValue($defaults['token'])->end()
175 ->end()
176 ->end();
177
178 return $treeBuilder;
179 }
180 }