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
{
18 public function getConfigTreeBuilder() {
19 //Get TreeBuilder object
20 $treeBuilder = new TreeBuilder('rapsys_pack');
22 //Get ExecutableFinder object
23 $finder = new ExecutableFinder();
26 * XXX: Note about the output schemes
28 * The output files are written based on the output.<ext> scheme with the * replaced by the hashed path of packed files
30 * The following service configuration make twig render the output file path with the right '/' basePath prefix:
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 ]
41 //The bundle default values
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',
51 'css' => '@RapsysPack/css/*.pack.css',
52 'js' => '@RapsysPack/js/*.pack.js',
53 'img' => '@RapsysPack/img/*.pack.jpg'
58 'class' => 'Rapsys\PackBundle\Twig\Filter\CPackFilter',
60 $finder->find('cpack', '/usr/local/bin/cpack'),
67 'class' => 'Rapsys\PackBundle\Twig\Filter\JPackFilter',
69 $finder->find('jpack', '/usr/local/bin/jpack'),
76 'class' => 'Rapsys\PackBundle\Twig\Filter\IPackFilter',
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
92 ->addDefaultsIfNotSet()
95 ->addDefaultsIfNotSet()
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()
104 ->arrayNode('output')
105 ->addDefaultsIfNotSet()
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()
112 ->arrayNode('filters')
113 ->addDefaultsIfNotSet()
116 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
117 ->addDefaultChildrenIfNoneSet()
120 ->scalarNode('class')
123 ->defaultValue($defaults['filters']['css'][0]['class'])
127 ->treatNullLike(array())
128 ->defaultValue($defaults['filters']['css'][0]['args'])
129 ->scalarPrototype()->end()
135 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
136 ->addDefaultChildrenIfNoneSet()
139 ->scalarNode('class')
142 ->defaultValue($defaults['filters']['js'][0]['class'])
145 ->treatNullLike(array())
146 ->defaultValue($defaults['filters']['js'][0]['args'])
147 ->scalarPrototype()->end()
153 #XXX: undocumented, see Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +513
154 ->addDefaultChildrenIfNoneSet()
157 ->scalarNode('class')
160 ->defaultValue($defaults['filters']['img'][0]['class'])
163 ->treatNullLike(array())
164 ->defaultValue($defaults['filters']['img'][0]['args'])
165 ->scalarPrototype()->end()