From: Raphaƫl Gertz Date: Tue, 3 Apr 2018 04:32:08 +0000 (+0200) Subject: Add bundle configuration system X-Git-Tag: 0.0.2~7 X-Git-Url: https://git.rapsys.eu/.gitweb.cgi/packbundle/commitdiff_plain/841a8835e903a514e2e44706bf4974f3cc21104b?ds=sidebyside Add bundle configuration system --- 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; + } } diff --git a/DependencyInjection/RapsysPackExtension.php b/DependencyInjection/RapsysPackExtension.php index b200abd..9bcd117 100644 --- a/DependencyInjection/RapsysPackExtension.php +++ b/DependencyInjection/RapsysPackExtension.php @@ -12,17 +12,19 @@ use Symfony\Component\DependencyInjection\Loader; * * @link http://symfony.com/doc/current/cookbook/bundles/extension.html */ -class RapsysPackExtension extends Extension -{ - /** - * {@inheritdoc} - */ - public function load(array $configs, ContainerBuilder $container) - { - $configuration = new Configuration(); - $config = $this->processConfiguration($configuration, $configs); +class RapsysPackExtension extends Extension { + /** + * {@inheritdoc} + */ + public function load(array $configs, ContainerBuilder $container) { + $configuration = new Configuration($container->getParameter('kernel.project_dir').'/web/'); + $config = $this->processConfiguration($configuration, $configs); - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.yml'); - } + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.yml'); + } + + public function getConfiguration(array $configs, ContainerBuilder $container) { + return new Configuration($container->getParameter('kernel.project_dir').'/web/'); + } }