Skip to content

Instantly share code, notes, and snippets.

@ger86
Created March 4, 2019 18:12
Show Gist options
  • Save ger86/0858d4f15976455ebfea803f5dea3637 to your computer and use it in GitHub Desktop.
Save ger86/0858d4f15976455ebfea803f5dea3637 to your computer and use it in GitHub Desktop.
<?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