]> Raphaƫl G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
Change tree to reflect configuration
[packbundle] / DependencyInjection / Configuration.php
1 <?php
2
3 namespace Rapsys\PackBundle\DependencyInjection;
4
5 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6 use Symfony\Component\Config\Definition\ConfigurationInterface;
7 use Symfony\Component\Process\ExecutableFinder;
8
9 /**
10 * This is the class that validates and merges configuration from your app/config files.
11 *
12 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
13 */
14 class Configuration implements ConfigurationInterface {
15 /**
16 * {@inheritdoc}
17 */
18 public function getConfigTreeBuilder() {
19 //Get TreeBuilder object
20 $treeBuilder = new TreeBuilder('rapsys_pack');
21
22 //Get ExecutableFinder object
23 $finder = new ExecutableFinder();
24
25 /**
26 * XXX: Note about the output schemes
27 *
28 * The output files are written based on the output.<ext> scheme with the * replaced by the hashed path of packed files
29 *
30 * The following service configuration make twig render the output file path with the right '/' basePath prefix:
31 * services:
32 * assets.pack_package:
33 * class: Rapsys\PackBundle\Asset\PathPackage
34 * arguments: [ '/', '@assets.empty_version_strategy', '@assets.context' ]
35 * rapsys_pack.twig.pack_extension:
36 * class: Rapsys\PackBundle\Twig\PackExtension
37 * arguments: [ '@file_locator', '@service_container', '@assets.pack_package' ]
38 * tags: [ twig.extension ]
39 */
40
41 //The bundle default values
42 $defaults = [
43 'config' => [
44 'name' => 'asset_url',
45 'scheme' => 'https://',
46 'timeout' => (int)ini_get('default_socket_timeout'),
47 'agent' => (string)ini_get('user_agent')?:'rapsys_pack/0.1.3',
48 'redirect' => 5
49 ],
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\Twig\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\Twig\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\Twig\Filter\IPackFilter',
77 'args' => []
78 ]
79 ],
80 ]
81 ];
82
83 //Here we define the parameters that are allowed to configure the bundle.
84 //XXX: see https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php for default value and description
85 //XXX: see http://symfony.com/doc/current/components/config/definition.html
86 //XXX: see https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
87 //XXX: see php bin/console config:dump-reference rapsys_pack to dump default config
88 //XXX: see php bin/console debug:config rapsys_pack to dump config
89 $treeBuilder
90 //Parameters
91 ->getRootNode()
92 ->addDefaultsIfNotSet()
93 ->children()
94 ->arrayNode('config')
95 ->addDefaultsIfNotSet()
96 ->children()
97 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['config']['name'])->end()
98 ->scalarNode('scheme')->cannotBeEmpty()->defaultValue($defaults['config']['scheme'])->end()
99 ->integerNode('timeout')->min(0)->max(300)->defaultValue($defaults['config']['timeout'])->end()
100 ->scalarNode('agent')->cannotBeEmpty()->defaultValue($defaults['config']['agent'])->end()
101 ->integerNode('redirect')->min(1)->max(30)->defaultValue($defaults['config']['redirect'])->end()
102 ->end()
103 ->end()
104 ->arrayNode('output')
105 ->addDefaultsIfNotSet()
106 ->children()
107 ->scalarNode('css')->cannotBeEmpty()->defaultValue($defaults['output']['css'])->end()
108 ->scalarNode('js')->cannotBeEmpty()->defaultValue($defaults['output']['js'])->end()
109 ->scalarNode('img')->cannotBeEmpty()->defaultValue($defaults['output']['img'])->end()
110 ->end()
111 ->end()
112 ->arrayNode('filters')
113 ->addDefaultsIfNotSet()
114 ->children()
115 ->arrayNode('css')
116 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
117 ->addDefaultChildrenIfNoneSet()
118 ->arrayPrototype()
119 ->children()
120 ->scalarNode('class')
121 ->isRequired()
122 ->cannotBeEmpty()
123 ->defaultValue($defaults['filters']['css'][0]['class'])
124 ->end()
125 ->arrayNode('args')
126 /*->isRequired()*/
127 ->treatNullLike(array())
128 ->defaultValue($defaults['filters']['css'][0]['args'])
129 ->scalarPrototype()->end()
130 ->end()
131 ->end()
132 ->end()
133 ->end()
134 ->arrayNode('js')
135 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
136 ->addDefaultChildrenIfNoneSet()
137 ->arrayPrototype()
138 ->children()
139 ->scalarNode('class')
140 ->isRequired()
141 ->cannotBeEmpty()
142 ->defaultValue($defaults['filters']['js'][0]['class'])
143 ->end()
144 ->arrayNode('args')
145 ->treatNullLike(array())
146 ->defaultValue($defaults['filters']['js'][0]['args'])
147 ->scalarPrototype()->end()
148 ->end()
149 ->end()
150 ->end()
151 ->end()
152 ->arrayNode('img')
153 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
154 ->addDefaultChildrenIfNoneSet()
155 ->arrayPrototype()
156 ->children()
157 ->scalarNode('class')
158 ->isRequired()
159 ->cannotBeEmpty()
160 ->defaultValue($defaults['filters']['img'][0]['class'])
161 ->end()
162 ->arrayNode('args')
163 ->treatNullLike(array())
164 ->defaultValue($defaults['filters']['img'][0]['args'])
165 ->scalarPrototype()->end()
166 ->end()
167 ->end()
168 ->end()
169 ->end()
170 ->end()
171 ->end()
172 ->end()
173 ->end();
174
175 return $treeBuilder;
176 }
177 }