]> Raphaƫl G. Git Repositories - packbundle/blob - DependencyInjection/Configuration.php
Fix readme
[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(string $projectDir) {
17 $this->projectDir = $projectDir;
18 }
19
20 /**
21 * {@inheritdoc}
22 */
23 public function getConfigTreeBuilder() {
24 $treeBuilder = new TreeBuilder();
25 $finder = new ExecutableFinder();
26
27 #TODO: see how we deal with asset url generation: see Rapsys/PackBundle/Twig/PackTokenParser.php +243
28 #framework:
29 # assets:
30 # packages:
31 # rapsys_pack:
32 # base_path: '/'
33 # version: ~
34 #
35 ## Force cache disable to regenerate resources each time
36 ##twig:
37 ## cache: ~
38
39 //Here we define the parameters that are allowed to configure the bundle.
40 //TODO: see https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php for default value and description
41 //TODO: see http://symfony.com/doc/current/components/config/definition.html
42 //TODO: see https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63
43 //TODO: use bin/console config:dump-reference to dump class infos
44 $treeBuilder
45 //Parameters
46 ->root('parameters')
47 ->children()
48 ->arrayNode('rapsys_pack')
49 ->children()
50 ->scalarNode('coutput')->defaultValue('css/*.pack.css')->end()
51 ->scalarNode('joutput')->defaultValue('js/*.pack.js')->end()
52 ->scalarNode('ioutput')->defaultValue('img/*.pack.jpg')->end()
53 ->arrayNode('cfilter')
54 ->treatNullLike(array())
55 ->scalarPrototype()->end()
56 ->defaultValue(array('Rapsys\PackBundle\Twig\Filter\CPackFilter'))
57 ->end()
58 ->arrayNode('jfilter')
59 ->treatNullLike(array())
60 ->scalarPrototype()->end()
61 ->defaultValue(array('Rapsys\PackBundle\Twig\Filter\JPackFilter'))
62 ->end()
63 ->arrayNode('ifilter')
64 ->treatNullLike(array())
65 ->scalarPrototype()->end()
66 ->defaultValue(array('Rapsys\PackBundle\Twig\Filter\IPackFilter'))
67 ->end()
68 ->scalarNode('prefix')->defaultValue($this->projectDir)->end()
69 ->scalarNode('scheme')->defaultValue('https://')->end()
70 ->integerNode('timeout')->min(0)->defaultValue((int)ini_get('default_socket_timeout'))->end()
71 ->scalarNode('agent')->defaultValue(ini_get('user_agent'))->end()
72 ->integerNode('redirect')->min(1)->defaultValue(20)->end()
73 ->end()
74 ->end()
75 ->arrayNode('rapsys_pack_cpackfilter')
76 ->children()
77 ->scalarNode('bin')->defaultValue(function () use ($finder) { return $finder->find('cpack', '/usr/local/bin/cpack'); })->end()
78 ->end()
79 ->end()
80 ->arrayNode('rapsys_pack_jpackfilter')
81 ->children()
82 ->scalarNode('bin')->defaultValue(function () use ($finder) { return $finder->find('jpack', '/usr/local/bin/jpack'); })->end()
83 ->end()
84 ->end()
85 ->end()
86 ->end();
87
88 return $treeBuilder;
89 }
90 }