Created
March 4, 2019 18:12
-
-
Save ger86/0858d4f15976455ebfea803f5dea3637 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace App; | |
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | |
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\HttpKernel\Kernel as BaseKernel; | |
class ShortcodesPass extends BaseKernel implements CompilerPassInterface { | |
public function process(ContainerBuilder $container) | |
if (!$container->has('App\Shortcode\ShortcodeService')) { | |
return; | |
} | |
// get the ShortcodeService | |
$definition = $container->findDefinition('App\Shortcode\ShortcodeService'); | |
// find all the services with tag lac.shortcode | |
$taggedServices = $container->findTaggedServiceIds('lac.shortcode'); | |
foreach ($taggedServices as $id => $tags) { | |
// call method addShortcode of App\Shortcode\ShortcodeService with the tagged services | |
$definition->addMethodCall('addShortcode', array(new Reference($id))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment