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\Contracts\Service\ResetInterface;
15
 
16
/**
17
 * Resets provided services.
18
 *
19
 * @author Alexander M. Turek <me@derrabus.de>
20
 * @author Nicolas Grekas <p@tchwork.com>
21
 *
22
 * @internal
23
 */
24
class ServicesResetter implements ResetInterface
25
{
26
    private \Traversable $resettableServices;
27
    private array $resetMethods;
28
 
29
    /**
30
     * @param \Traversable<string, object>   $resettableServices
31
     * @param array<string, string|string[]> $resetMethods
32
     */
33
    public function __construct(\Traversable $resettableServices, array $resetMethods)
34
    {
35
        $this->resettableServices = $resettableServices;
36
        $this->resetMethods = $resetMethods;
37
    }
38
 
39
    public function reset()
40
    {
41
        foreach ($this->resettableServices as $id => $service) {
42
            foreach ((array) $this->resetMethods[$id] as $resetMethod) {
43
                if ('?' === $resetMethod[0] && !method_exists($service, $resetMethod = substr($resetMethod, 1))) {
44
                    continue;
45
                }
46
 
47
                $service->$resetMethod();
48
            }
49
        }
50
    }
51
}