mirror of
https://github.com/KnpLabs/KnpMarkdownBundle.git
synced 2024-06-09 01:12:12 +02:00
bd597e66a1
Fix detection of default parser when none is set Add Flavored preset from KnpBundles.com
37 lines
1.3 KiB
PHP
37 lines
1.3 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('templating.helper.markdown')) {
|
|
return;
|
|
}
|
|
|
|
if (!$definition = $container->findDefinition('markdown.parser')) {
|
|
return;
|
|
}
|
|
|
|
$defaultAlias = current($definition->getTag('markdown.parser'));
|
|
$defaultAlias = $defaultAlias['alias'];
|
|
$definition = $container->getDefinition('templating.helper.markdown');
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|