Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
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\Argument\IteratorArgument;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
19
use Symfony\Component\DependencyInjection\Reference;
20
 
21
/**
22
 * @author Alexander M. Turek <me@derrabus.de>
23
 */
24
class ResettableServicePass implements CompilerPassInterface
25
{
26
    public function process(ContainerBuilder $container)
27
    {
28
        if (!$container->has('services_resetter')) {
29
            return;
30
        }
31
 
32
        $services = $methods = [];
33
 
34
        foreach ($container->findTaggedServiceIds('kernel.reset', true) as $id => $tags) {
35
            $services[$id] = new Reference($id, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE);
36
 
37
            foreach ($tags as $attributes) {
38
                if (!isset($attributes['method'])) {
39
                    throw new RuntimeException(sprintf('Tag "kernel.reset" requires the "method" attribute to be set on service "%s".', $id));
40
                }
41
 
42
                if (!isset($methods[$id])) {
43
                    $methods[$id] = [];
44
                }
45
 
46
                if ('ignore' === ($attributes['on_invalid'] ?? null)) {
47
                    $attributes['method'] = '?'.$attributes['method'];
48
                }
49
 
50
                $methods[$id][] = $attributes['method'];
51
            }
52
        }
53
 
54
        if (!$services) {
55
            $container->removeAlias('services_resetter');
56
            $container->removeDefinition('services_resetter');
57
 
58
            return;
59
        }
60
 
61
        $container->findDefinition('services_resetter')
62
            ->setArgument(0, new IteratorArgument($services))
63
            ->setArgument(1, $methods);
64
    }
65
}