Skip to content

Commit

Permalink
feature: add a slug compiler pass to allow multiple slug generator ta…
Browse files Browse the repository at this point in the history
…gged services
  • Loading branch information
johnkrovitch committed Oct 28, 2023
1 parent f7cd2bf commit 3d6a17c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/DependencyInjection/CompilerPass/SlugMappingCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace LAG\AdminBundle\DependencyInjection\CompilerPass;

use LAG\AdminBundle\Slug\Generator\CompositeSlugGenerator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class SlugMappingCompilerPass implements CompilerPassInterface
{

public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition(CompositeSlugGenerator::class)) {
return;
}
$generators = [];

foreach ($container->findTaggedServiceIds('lag_admin.slug_generator') as $id => $tags) {
foreach ($tags as $tag) {
$generators[$tag['generator']] = new Reference($id);
}
}
$definition = $container->getDefinition(CompositeSlugGenerator::class);
$definition->setLazy(true);
$definition->setArgument('$generators', $generators);
}
}

0 comments on commit 3d6a17c

Please sign in to comment.