| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|
|
15 |
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
|
|
|
16 |
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
17 |
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
|
|
18 |
use Symfony\Component\DependencyInjection\Reference;
|
|
|
19 |
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Adds services tagged kernel.fragment_renderer as HTTP content rendering strategies.
|
|
|
23 |
*
|
|
|
24 |
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
25 |
*/
|
|
|
26 |
class FragmentRendererPass implements CompilerPassInterface
|
|
|
27 |
{
|
|
|
28 |
public function process(ContainerBuilder $container)
|
|
|
29 |
{
|
|
|
30 |
if (!$container->hasDefinition('fragment.handler')) {
|
|
|
31 |
return;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
$definition = $container->getDefinition('fragment.handler');
|
|
|
35 |
$renderers = [];
|
|
|
36 |
foreach ($container->findTaggedServiceIds('kernel.fragment_renderer', true) as $id => $tags) {
|
|
|
37 |
$def = $container->getDefinition($id);
|
|
|
38 |
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
|
|
39 |
|
|
|
40 |
if (!$r = $container->getReflectionClass($class)) {
|
|
|
41 |
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
|
|
|
42 |
}
|
|
|
43 |
if (!$r->isSubclassOf(FragmentRendererInterface::class)) {
|
|
|
44 |
throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, FragmentRendererInterface::class));
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
foreach ($tags as $tag) {
|
|
|
48 |
$renderers[$tag['alias']] = new Reference($id);
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
$definition->replaceArgument(0, ServiceLocatorTagPass::register($container, $renderers));
|
|
|
53 |
}
|
|
|
54 |
}
|