mirror of
https://github.com/KnpLabs/KnpMarkdownBundle.git
synced 2024-06-26 09:20:07 +02:00
This allows the Twig extension to be used without the templating component. This also introduces a new integration test as a sanity check that all the configuration / compiler pass was setup correctly.
44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Knp\Bundle\MarkdownBundle\DependencyInjection\Compiler;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
class ParsersCompilerPass implements CompilerPassInterface
|
|
{
|
|
public function process(ContainerBuilder $container)
|
|
{
|
|
if (!$container->hasDefinition('markdown.parser.parser_manager')) {
|
|
return;
|
|
}
|
|
|
|
if (!$definition = $container->findDefinition('markdown.parser')) {
|
|
return;
|
|
}
|
|
|
|
$defaultAlias = $definition->getTag('markdown.parser');
|
|
if (!empty($defaultAlias)) {
|
|
$defaultAlias = current($defaultAlias);
|
|
$defaultAlias = isset($defaultAlias['alias']) ? $defaultAlias['alias'] : null;
|
|
}
|
|
|
|
$definition = $container->getDefinition('markdown.parser.parser_manager');
|
|
if (empty($defaultAlias)) {
|
|
$definition->addMethodCall('addParser', array(new Reference('markdown.parser'), 'default'));
|
|
}
|
|
|
|
foreach ($container->findTaggedServiceIds('markdown.parser') as $id => $tags) {
|
|
foreach ($tags as $attributes) {
|
|
$alias = empty($attributes['alias']) ? $id : $attributes['alias'];
|
|
if ($defaultAlias == $alias) {
|
|
$definition->addMethodCall('addParser', array(new Reference($id), 'default'));
|
|
} else {
|
|
$definition->addMethodCall('addParser', array(new Reference($id), $alias));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|