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