3 namespace Rapsys\PackBundle\DependencyInjection
;
5 use Symfony\Component\Config\Definition\Builder\TreeBuilder
;
6 use Symfony\Component\Config\Definition\ConfigurationInterface
;
7 use Symfony\Component\Process\ExecutableFinder
;
10 * This is the class that validates and merges configuration from your app/config files.
12 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
14 class Configuration
implements ConfigurationInterface
{
15 //Constructor required to derivate prefix from kernel.project_dir
16 public function __construct($projectDir) {
17 $this->projectDir
= $projectDir;
23 public function getConfigTreeBuilder() {
24 //Get TreeBuilder object
25 $treeBuilder = new TreeBuilder();
27 //Get ExecutableFinder object
28 $finder = new ExecutableFinder();
30 #TODO: see how we deal with asset url generation: see Rapsys/PackBundle/Twig/PackTokenParser.php +243
38 ## Force cache disable to regenerate resources each time
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
47 //The bundle default values
50 'prefix' => $this->projectDir
,
51 'scheme' => 'https://',
52 'timeout' => (int)ini_get('default_socket_timeout'),
53 'agent' => (string)ini_get('user_agent')?:'rapsys_pack/0.0.2',
57 'css' => 'css/*.pack.css',
58 'js' => 'js/*.pack.js',
59 'img' => 'img/*.pack.jpg'
63 'Rapsys\PackBundle\Twig\Filter\CPackFilter' => [$finder->find('cpack', '/usr/local/bin/cpack')]
66 'Rapsys\PackBundle\Twig\Filter\JPackFilter' => [$finder->find('jpack', '/usr/local/bin/jpack')]
69 'Rapsys\PackBundle\Twig\Filter\IPackFilter' => []
74 //Here we define the parameters that are allowed to configure the bundle.
79 ->addDefaultsIfNotSet()
81 ->arrayNode('rapsys_pack')
83 ->addDefaultsIfNotSet()
87 ->addDefaultsIfNotSet()
89 ->scalarNode('prefix')->isRequired()->defaultValue($defaults['config']['prefix'])->end()
90 ->scalarNode('scheme')->isRequired()->defaultValue($defaults['config']['scheme'])->end()
91 ->integerNode('timeout')->isRequired()->min(0)->defaultValue($defaults['config']['timeout'])->end()
92 ->scalarNode('agent')->isRequired()->defaultValue($defaults['config']['agent'])->end()
93 ->integerNode('redirect')->isRequired()->min(1)->defaultValue($defaults['config']['redirect'])->end()
98 ->addDefaultsIfNotSet()
100 ->scalarNode('css')->isRequired()->defaultValue($defaults['output']['css'])->end()
101 ->scalarNode('js')->isRequired()->defaultValue($defaults['output']['js'])->end()
102 ->scalarNode('img')->isRequired()->defaultValue($defaults['output']['img'])->end()
105 ->arrayNode('filter')
107 ->addDefaultsIfNotSet()
111 ->treatNullLike(array())
112 ->scalarPrototype()->end()
113 ->defaultValue($defaults['filter']['css'])
117 ->treatNullLike(array())
118 ->scalarPrototype()->end()
119 ->defaultValue($defaults['filter']['js'])
123 ->treatNullLike(array())
124 ->scalarPrototype()->end()
125 ->defaultValue($defaults['filter']['img'])