2011-02-25 12:34:20 +01:00
|
|
|
<?php
|
|
|
|
|
2011-07-03 11:28:55 +02:00
|
|
|
namespace Knp\Bundle\MarkdownBundle\DependencyInjection;
|
2011-02-25 12:34:20 +01:00
|
|
|
|
2017-11-29 19:29:54 +01:00
|
|
|
use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
|
|
|
|
use Michelf\MarkdownInterface;
|
2011-02-25 12:34:20 +01:00
|
|
|
use Symfony\Component\Config\FileLocator;
|
2012-10-15 12:24:11 +02:00
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
2017-11-29 19:18:19 +01:00
|
|
|
use Symfony\Component\DependencyInjection\Alias;
|
2011-02-25 12:34:20 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2012-10-15 12:24:11 +02:00
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
2018-01-23 02:43:42 +01:00
|
|
|
use Symfony\Component\Templating\EngineInterface;
|
2011-02-25 12:34:20 +01:00
|
|
|
|
2011-07-03 11:28:55 +02:00
|
|
|
class KnpMarkdownExtension extends Extension
|
2011-02-25 12:34:20 +01:00
|
|
|
{
|
2011-02-25 15:43:59 +01:00
|
|
|
/**
|
2011-07-03 11:28:55 +02:00
|
|
|
* Handles the knp_markdown configuration.
|
2011-02-25 15:43:59 +01:00
|
|
|
*
|
2012-10-15 12:24:11 +02:00
|
|
|
* @param array $configs The configurations being loaded
|
2011-02-25 15:43:59 +01:00
|
|
|
* @param ContainerBuilder $container
|
2012-10-15 12:24:11 +02:00
|
|
|
*
|
|
|
|
* @throws InvalidConfigurationException When Sundown parser was selected, but extension is not available
|
2011-02-25 15:43:59 +01:00
|
|
|
*/
|
2011-02-25 12:34:20 +01:00
|
|
|
public function load(array $configs , ContainerBuilder $container)
|
|
|
|
{
|
2011-04-07 08:35:00 +02:00
|
|
|
$configuration = new Configuration();
|
2011-02-25 12:34:20 +01:00
|
|
|
|
2012-10-10 18:01:45 +02:00
|
|
|
$config = $this->processConfiguration($configuration, $configs);
|
2011-02-25 12:34:20 +01:00
|
|
|
|
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
|
|
|
$loader->load('parser.xml');
|
2018-01-23 02:43:42 +01:00
|
|
|
// BC to support the PHP templates in the Templating component
|
|
|
|
if (interface_exists(EngineInterface::class)) {
|
|
|
|
$loader->load('helper.xml');
|
|
|
|
}
|
2011-02-25 12:34:20 +01:00
|
|
|
$loader->load('twig.xml');
|
|
|
|
|
2012-10-17 12:00:37 +02:00
|
|
|
if ('markdown.parser.sundown' == $config['parser']['service']) {
|
|
|
|
if (!class_exists('Sundown\\Markdown')) {
|
|
|
|
throw new InvalidConfigurationException('Sundown parser selected, but required extension is not installed or configured.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$loader->load('sundown.xml');
|
|
|
|
|
|
|
|
$definition = $container->getDefinition('markdown.parser.sundown');
|
|
|
|
$definition->addTag('markdown.parser', array('alias' => 'sundown'));
|
|
|
|
|
|
|
|
$container->setParameter('markdown.sundown.extensions', $config['sundown']['extensions']);
|
|
|
|
$container->setParameter('markdown.sundown.render_flags', $config['sundown']['render_flags']);
|
2012-10-15 12:24:11 +02:00
|
|
|
}
|
|
|
|
|
2017-11-29 19:18:19 +01:00
|
|
|
$container->setAlias('markdown.parser', new Alias($config['parser']['service'], true));
|
2017-11-29 19:29:54 +01:00
|
|
|
$container->setAlias(MarkdownParserInterface::class, 'markdown.parser');
|
|
|
|
$container->setAlias(MarkdownInterface::class, 'markdown.parser');
|
2011-02-25 12:34:20 +01:00
|
|
|
}
|
|
|
|
}
|