-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add a slug compiler pass to allow multiple slug generator ta…
…gged services
- Loading branch information
1 parent
f7cd2bf
commit 3d6a17c
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/DependencyInjection/CompilerPass/SlugMappingCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |