1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
abstract class AbstractServiceConfigurator extends AbstractConfigurator
{
protected $parent;
protected $id;
private $defaultTags = [];
public function __construct(ServicesConfigurator $parent, Definition $definition, string $id = null, array $defaultTags = [])
{
$this->parent = $parent;
$this->definition = $definition;
$this->id = $id;
$this->defaultTags = $defaultTags;
}
public function __destruct()
{
// default tags should be added last
foreach ($this->defaultTags as $name => $attributes) {
foreach ($attributes as $attributes) {
$this->definition->addTag($name, $attributes);
}
}
$this->defaultTags = [];
}
/**
* Registers a service.
*/
final public function set(string $id, string $class = null): ServiceConfigurator
{
$this->__destruct();
return $this->parent->set($id, $class);
}
/**
* Creates an alias.
*/
final public function alias(string $id, string $referencedId): AliasConfigurator
{
$this->__destruct();
return $this->parent->alias($id, $referencedId);
}
/**
* Registers a PSR-4 namespace using a glob pattern.
*/
final public function load(string $namespace, string $resource): PrototypeConfigurator
{
$this->__destruct();
return $this->parent->load($namespace, $resource);
}
/**
* Gets an already defined service definition.
*
* @throws ServiceNotFoundException if the service definition does not exist
*/
final public function get(string $id): ServiceConfigurator
{
$this->__destruct();
return $this->parent->get($id);
}
/**
* Registers a service.
*/
final public function __invoke(string $id, string $class = null): ServiceConfigurator
{
$this->__destruct();
return $this->parent->set($id, $class);
}
}