diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php new file mode 100644 index 0000000..08da2b3 --- /dev/null +++ b/DependencyInjection/Configuration.php @@ -0,0 +1,33 @@ +root('knplabs_markdown', 'array') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('parser') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('service')->cannotBeEmpty()->defaultValue('markdown.parser.max')->end() + ->end() + ->end() + ->end() + ->end(); + + return $treeBuilder->buildTree(); + } +} diff --git a/DependencyInjection/KnplabsMarkdownExtension.php b/DependencyInjection/KnplabsMarkdownExtension.php index 239409c..115d47a 100644 --- a/DependencyInjection/KnplabsMarkdownExtension.php +++ b/DependencyInjection/KnplabsMarkdownExtension.php @@ -2,6 +2,7 @@ namespace Knplabs\Bundle\MarkdownBundle\DependencyInjection; +use Symfony\Component\Config\Definition\Processor; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\Config\FileLocator; @@ -17,87 +18,16 @@ class KnplabsMarkdownExtension extends Extension */ public function load(array $configs , ContainerBuilder $container) { - $config = array(); - foreach($configs as $c) { - $config = array_merge($config, $c); - } + $processor = new Processor(); + $configuration = new Configuration(); - if(array_key_exists('parser', $config)) { - $this->parserLoad($config, $container); - } - - if(array_key_exists('helper', $config)) { - $this->helperLoad($config, $container); - } + $config = $processor->process($configuration->getConfigTree(), $configs); - if(array_key_exists('twig', $config)) { - $this->twigLoad($config, $container); - } - } - - /** - * Handles the parser configuration. - * - * @param array $config The configurations being loaded - * @param ContainerBuilder $container - */ - public function parserLoad($config, ContainerBuilder $container) - { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('parser.xml'); - - if(isset($config['parser']['class'])) { - $container->setParameter('markdown.parser.class', $config['parser']['class']); - } - } - - /** - * Handles the helper configuration. - * - * @param array $config The configurations being loaded - * @param ContainerBuilder $container - */ - public function helperLoad($config, ContainerBuilder $container) - { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('helper.xml'); - } - - /** - * Handles the twig configuration. - * - * @param array $config The configurations being loaded - * @param ContainerBuilder $container - */ - public function twigLoad($config, ContainerBuilder $container) - { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('twig.xml'); - } - /** - * Returns the base path for the XSD files. - * - * @return string The XSD base path - */ - public function getXsdValidationBasePath() - { - return null; - } - - /** - * @see Symfony\Component\DependencyInjection\Extension\ExtensionInterface - */ - public function getNamespace() - { - return 'http://www.symfony-project.org/schema/dic/markdown'; - } - - /** - * @see Symfony\Component\DependencyInjection\Extension\ExtensionInterface - */ - public function getAlias() - { - return 'knplabs_markdown'; + $container->setAlias('markdown.parser', $config['parser']['service']); } } diff --git a/MarkdownParserInterface.php b/MarkdownParserInterface.php new file mode 100644 index 0000000..99df22e --- /dev/null +++ b/MarkdownParserInterface.php @@ -0,0 +1,14 @@ + - + - + diff --git a/Resources/config/parser.xml b/Resources/config/parser.xml index fe94918..94958a9 100644 --- a/Resources/config/parser.xml +++ b/Resources/config/parser.xml @@ -4,31 +4,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - Knplabs\Bundle\MarkdownBundle\Parser\Preset\Min - Knplabs\Bundle\MarkdownBundle\Parser\Preset\Light - Knplabs\Bundle\MarkdownBundle\Parser\Preset\Medium - Knplabs\Bundle\MarkdownBundle\Parser\Preset\Max - - %markdown.parser.max.class% - - - - Knplabs\Bundle\MarkdownBundle\Helper\MarkdownHelper - - - - - - %markdown.parser.features% - - - - - - - + + + + + diff --git a/Resources/config/twig.xml b/Resources/config/twig.xml index cc6d1ef..c958ad3 100644 --- a/Resources/config/twig.xml +++ b/Resources/config/twig.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - +