X-Git-Url: https://git.rapsys.eu/packbundle/blobdiff_plain/e558fbb8ca84a4013182f56a30b83f6bcad28022..841a8835e903a514e2e44706bf4974f3cc21104b:/DependencyInjection/Configuration.php?ds=inline diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 2553598..2e64eed 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -4,38 +4,87 @@ namespace Rapsys\PackBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\Process\ExecutableFinder; /** * This is the class that validates and merges configuration from your app/config files. * * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html} */ -class Configuration implements ConfigurationInterface -{ - /** - * {@inheritdoc} - */ - public function getConfigTreeBuilder() - { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('rapsys_pack'); +class Configuration implements ConfigurationInterface { + //Constructor required to derivate prefix from kernel.project_dir + public function __construct(string $projectDir) { + $this->projectDir = $projectDir; + } - // Here you should define the parameters that are allowed to - // configure your bundle. See the documentation linked above for - // more information on that topic. + /** + * {@inheritdoc} + */ + public function getConfigTreeBuilder() { + $treeBuilder = new TreeBuilder(); + $finder = new ExecutableFinder(); - //TODO: see https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php for default value and description - //TODO: see http://symfony.com/doc/current/components/config/definition.html - //TODO: use bin/console config:dump-reference to dump class infos - $rootNode - ->children() - ->scalarNode('jpack')->end() - ->scalarNode('cpack')->end() - ->scalarNode('prefix')->end() - ->scalarNode('scheme')->end() - ->integerNode('timeout')->end() - ->end(); + #TODO: see how we deal with asset url generation: see Rapsys/PackBundle/Twig/PackTokenParser.php +243 + #framework: + # assets: + # packages: + # rapsys_pack: + # base_path: '/' + # version: ~ + # + ## Force cache disable to regenerate resources each time + ##twig: + ## cache: ~ - return $treeBuilder; - } + //Here we define the parameters that are allowed to configure the bundle. + //TODO: see https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php for default value and description + //TODO: see http://symfony.com/doc/current/components/config/definition.html + //TODO: see https://github.com/symfony/assetic-bundle/blob/master/DependencyInjection/Configuration.php#L63 + //TODO: use bin/console config:dump-reference to dump class infos + $treeBuilder + //Parameters + ->root('parameters') + ->children() + ->arrayNode('rapsys_pack') + ->children() + ->scalarNode('coutput')->defaultValue('css/*.pack.css')->end() + ->scalarNode('joutput')->defaultValue('js/*.pack.js')->end() + ->scalarNode('ioutput')->defaultValue('img/*.pack.jpg')->end() + ->arrayNode('cfilter') + ->treatNullLike(array()) + ->scalarPrototype()->end() + ->defaultValue(array('Rapsys\PackBundle\Twig\Filter\CPackFilter')) + ->end() + ->arrayNode('jfilter') + ->treatNullLike(array()) + ->scalarPrototype()->end() + ->defaultValue(array('Rapsys\PackBundle\Twig\Filter\JPackFilter')) + ->end() + ->arrayNode('ifilter') + ->treatNullLike(array()) + ->scalarPrototype()->end() + ->defaultValue(array('Rapsys\PackBundle\Twig\Filter\IPackFilter')) + ->end() + ->scalarNode('prefix')->defaultValue($this->projectDir)->end() + ->scalarNode('scheme')->defaultValue('https://')->end() + ->integerNode('timeout')->min(0)->defaultValue((int)ini_get('default_socket_timeout'))->end() + ->scalarNode('agent')->defaultValue(ini_get('user_agent'))->end() + ->integerNode('redirect')->min(1)->defaultValue(20)->end() + ->end() + ->end() + ->arrayNode('rapsys_pack_cpackfilter') + ->children() + ->scalarNode('bin')->defaultValue(function () use ($finder) { return $finder->find('cpack', '/usr/local/bin/cpack'); })->end() + ->end() + ->end() + ->arrayNode('rapsys_pack_jpackfilter') + ->children() + ->scalarNode('bin')->defaultValue(function () use ($finder) { return $finder->find('jpack', '/usr/local/bin/jpack'); })->end() + ->end() + ->end() + ->end() + ->end(); + + return $treeBuilder; + } }