]> Raphaƫl G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
Import post install file
[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 //Constructor required to derivate prefix from kernel.project_dir
16 public function __construct($projectDir) {
17 $this->projectDir = $projectDir;
18 }
19
20 /**
21 * {@inheritdoc}
22 */
23 public function getConfigTreeBuilder() {
24 //Get TreeBuilder object
25 $treeBuilder = new TreeBuilder();
26
27 //Get ExecutableFinder object
28 $finder = new ExecutableFinder();
29
30 #TODO: see how we deal with asset url generation: see Rapsys/PackBundle/Twig/PackTokenParser.php +243
31 #framework:
32 # assets:
33 # packages:
34 # rapsys_pack:
35 # base_path: '/'
36 # version: ~
37 #
38 ## Force cache disable to regenerate resources each time
39 ##twig:
40 ## cache: ~
41
42 //TODO: see https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php for default value and description
43 //TODO: see http://symfony.com/doc/current/components/config/definition.html
44 //TODO: see https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
45 //TODO: use bin/console config:dump-reference to dump class infos
46
47 //The bundle default values
48 $defaults = [
49 'config' => [
50 'prefix' => $this->projectDir,
51 'name' => 'asset_url',
52 'scheme' => 'https://',
53 'timeout' => (int)ini_get('default_socket_timeout'),
54 'agent' => (string)ini_get('user_agent')?:'rapsys_pack/0.0.2',
55 'redirect' => 5
56 ],
57 'output' => [
58 'css' => 'css/*.pack.css',
59 'js' => 'js/*.pack.js',
60 'img' => 'img/*.pack.jpg'
61 ],
62 'filters' => [
63 'css' => [
64 'class' => 'Rapsys\PackBundle\Twig\Filter\CPackFilter',
65 'args' => [
66 $finder->find('cpack', '/usr/local/bin/cpack'),
67 'minify'
68 ]
69 ],
70 'js' => [
71 'class' => 'Rapsys\PackBundle\Twig\Filter\JPackFilter',
72 'args' => [
73 $finder->find('jpack', '/usr/local/bin/jpack'),
74 'best'
75 ]
76 ],
77 'img' => [
78 'class' => 'Rapsys\PackBundle\Twig\Filter\IPackFilter',
79 'args' => []
80 ],
81 ]
82 ];
83
84 //Here we define the parameters that are allowed to configure the bundle.
85 $treeBuilder
86 //Parameters
87 ->root('parameters')
88 ->addDefaultsIfNotSet()
89 ->children()
90 ->arrayNode('rapsys_pack')
91 ->addDefaultsIfNotSet()
92 ->children()
93 ->arrayNode('config')
94 ->isRequired()
95 ->addDefaultsIfNotSet()
96 ->children()
97 ->scalarNode('prefix')->isRequired()->defaultValue($defaults['config']['prefix'])->end()
98 ->scalarNode('name')->isRequired()->defaultValue($defaults['config']['name'])->end()
99 ->scalarNode('scheme')->isRequired()->defaultValue($defaults['config']['scheme'])->end()
100 ->integerNode('timeout')->isRequired()->min(0)->defaultValue($defaults['config']['timeout'])->end()
101 ->scalarNode('agent')->isRequired()->defaultValue($defaults['config']['agent'])->end()
102 ->integerNode('redirect')->isRequired()->min(1)->defaultValue($defaults['config']['redirect'])->end()
103 ->end()
104 ->end()
105 ->arrayNode('output')
106 ->isRequired()
107 ->addDefaultsIfNotSet()
108 ->children()
109 ->scalarNode('css')->isRequired()->defaultValue($defaults['output']['css'])->end()
110 ->scalarNode('js')->isRequired()->defaultValue($defaults['output']['js'])->end()
111 ->scalarNode('img')->isRequired()->defaultValue($defaults['output']['img'])->end()
112 ->end()
113 ->end()
114 ->arrayNode('filters')
115 ->isRequired()
116 ->addDefaultsIfNotSet()
117 ->children()
118 ->arrayNode('css')
119 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
120 ->addDefaultChildrenIfNoneSet()
121 ->arrayPrototype()
122 ->children()
123 ->scalarNode('class')
124 ->isRequired()
125 ->defaultValue($defaults['filters']['css']['class'])
126 ->end()
127 ->arrayNode('args')
128 ->isRequired()
129 ->treatNullLike(array())
130 ->defaultValue($defaults['filters']['css']['args'])
131 ->scalarPrototype()->end()
132 ->end()
133 ->end()
134 ->end()
135 ->end()
136 ->arrayNode('js')
137 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
138 ->addDefaultChildrenIfNoneSet()
139 ->arrayPrototype()
140 ->children()
141 ->scalarNode('class')
142 ->isRequired()
143 ->defaultValue($defaults['filters']['js']['class'])
144 ->end()
145 ->arrayNode('args')
146 ->isRequired()
147 ->treatNullLike(array())
148 ->defaultValue($defaults['filters']['js']['args'])
149 ->scalarPrototype()->end()
150 ->end()
151 ->end()
152 ->end()
153 ->end()
154 ->arrayNode('img')
155 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
156 ->addDefaultChildrenIfNoneSet()
157 ->arrayPrototype()
158 ->children()
159 ->scalarNode('class')
160 ->isRequired()
161 ->defaultValue($defaults['filters']['img']['class'])
162 ->end()
163 ->arrayNode('args')
164 ->isRequired()
165 ->treatNullLike(array())
166 ->defaultValue($defaults['filters']['img']['args'])
167 ->scalarPrototype()->end()
168 ->end()
169 ->end()
170 ->end()
171 ->end()
172 ->end()
173 ->end()
174 ->end()
175 ->end()
176 ->end()
177 ->end();
178
179 return $treeBuilder;
180 }
181 }