1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Psr\Di\ProviderWrapper |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io-psr/di |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Psr\Di; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Lang\Reflection\AnnotationInterface; |
24
|
|
|
use AppserverIo\Psr\Deployment\DescriptorInterface; |
25
|
|
|
use AppserverIo\Psr\Application\ApplicationInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Wrapper implementation for a provider implementation. |
29
|
|
|
* |
30
|
|
|
* @author Tim Wagner <[email protected]> |
31
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/appserver-io-psr/di |
34
|
|
|
* @link http://www.appserver.io |
35
|
|
|
*/ |
36
|
|
|
class ProviderWrapper implements ProviderInterface |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The provider instance to be wrapped. |
41
|
|
|
* |
42
|
|
|
* @var \AppserverIo\Di\ProviderInterface |
43
|
|
|
*/ |
44
|
|
|
protected $provider; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Injects the passed provider instance into this wrapper. |
48
|
|
|
* |
49
|
|
|
* @param \AppserverIo\Psr\Di\ProviderInterface $provider The provider instance used for initialization |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function injectProvider(ProviderInterface $provider) |
54
|
|
|
{ |
55
|
|
|
$this->provider = $provider; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Return's the provider instance. |
60
|
|
|
* |
61
|
|
|
* @return \AppserverIo\Psr\Di\ProviderInterface The provider instance |
62
|
|
|
*/ |
63
|
|
|
public function getProvider() |
64
|
|
|
{ |
65
|
|
|
return $this->provider; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* The managers unique identifier. |
70
|
|
|
* |
71
|
|
|
* @return string The unique identifier |
72
|
|
|
*/ |
73
|
|
|
public function getIdentifier() |
74
|
|
|
{ |
75
|
|
|
return $this->getProvider()->getIdentifier(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Has been automatically invoked by the container after the application |
80
|
|
|
* instance has been created. |
81
|
|
|
* |
82
|
|
|
* @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance |
83
|
|
|
* |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
public function initialize(ApplicationInterface $application) |
87
|
|
|
{ |
88
|
|
|
$this->getProvider()->initialize($application); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns the value with the passed name from the context. |
93
|
|
|
* |
94
|
|
|
* @param string $key The key of the value to return from the context. |
95
|
|
|
* |
96
|
|
|
* @return mixed The requested attribute |
97
|
|
|
*/ |
98
|
|
|
public function getAttribute($key) |
99
|
|
|
{ |
100
|
|
|
return $this->getProvider()->getAttribute($key); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Returns the naming context instance. |
105
|
|
|
* |
106
|
|
|
* @return \AppserverIo\Psr\Naming\InitialContext The naming context instance |
107
|
|
|
*/ |
108
|
|
|
public function getInitialContext() |
109
|
|
|
{ |
110
|
|
|
return $this->getProvider()->getInitialContext(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns the applications naming directory. |
115
|
|
|
* |
116
|
|
|
* @return \AppserverIo\Psr\Naming\NamingDirectoryInterface The applications naming directory interface |
117
|
|
|
*/ |
118
|
|
|
public function getNamingDirectory() |
119
|
|
|
{ |
120
|
|
|
return $this->getProvider()->getNamingDirectory(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Creates a new new instance of the annotation type, defined in the passed reflection annotation. |
125
|
|
|
* |
126
|
|
|
* @param \AppserverIo\Lang\Reflection\AnnotationInterface $annotation The reflection annotation we want to create the instance for |
127
|
|
|
* |
128
|
|
|
* @return \AppserverIo\Lang\Reflection\AnnotationInterface The real annotation instance |
129
|
|
|
*/ |
130
|
|
|
public function newAnnotationInstance(AnnotationInterface $annotation) |
131
|
|
|
{ |
132
|
|
|
return $this->getProvider()->newAnnotationInstance($annotation); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Returns a new reflection class intance for the passed class name. |
137
|
|
|
* |
138
|
|
|
* @param string $className The class name to return the reflection class instance for |
139
|
|
|
* |
140
|
|
|
* @return \AppserverIo\Lang\Reflection\ReflectionClass The reflection instance |
141
|
|
|
*/ |
142
|
|
|
public function newReflectionClass($className) |
143
|
|
|
{ |
144
|
|
|
return $this->getProvider()->newReflectionClass($className); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Returns a reflection class intance for the passed class name. |
149
|
|
|
* |
150
|
|
|
* @param string $className The class name to return the reflection class instance for |
151
|
|
|
* |
152
|
|
|
* @return \AppserverIo\Lang\Reflection\ReflectionClass The reflection instance |
153
|
|
|
* @see \AppserverIo\Psr\Di\ProviderInterface::getReflectionClass() |
154
|
|
|
*/ |
155
|
|
|
public function getReflectionClass($className) |
156
|
|
|
{ |
157
|
|
|
return $this->getProvider()->getReflectionClass($className); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Returns a reflection class intance for the passed class name. |
162
|
|
|
* |
163
|
|
|
* @param object $instance The instance to return the reflection class instance for |
164
|
|
|
* |
165
|
|
|
* @return \AppserverIo\Lang\Reflection\ReflectionClass The reflection instance |
166
|
|
|
* @see \AppserverIo\Psr\Di\ProviderInterface::newReflectionClass() |
167
|
|
|
* @see \AppserverIo\Psr\Di\ProviderInterface::getReflectionClass() |
168
|
|
|
*/ |
169
|
|
|
public function getReflectionClassForObject($instance) |
170
|
|
|
{ |
171
|
|
|
return $this->getProvider()->getReflectionClassForObject($instance); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Returns a new instance of the passed class name. |
176
|
|
|
* |
177
|
|
|
* @param string $className The fully qualified class name to return the instance for |
178
|
|
|
* @param array $args Arguments to pass to the constructor of the instance |
179
|
|
|
* |
180
|
|
|
* @return object The instance itself |
181
|
|
|
*/ |
182
|
|
|
public function newInstance($className, array $args = array()) |
183
|
|
|
{ |
184
|
|
|
return $this->getProvider()->newInstance($className, $args); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Injects the dependencies of the passed instance defined in the object descriptor. |
189
|
|
|
* |
190
|
|
|
* |
191
|
|
|
* @param \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor The object descriptor with the dependencies |
192
|
|
|
* @param object $instance The instance to inject the dependencies for |
193
|
|
|
* |
194
|
|
|
* @return void |
195
|
|
|
*/ |
196
|
|
|
public function injectDependencies(DescriptorInterface $objectDescriptor, $instance) |
197
|
|
|
{ |
198
|
|
|
$this->getProvider()->injectDependencies($objectDescriptor, $instance); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Finds an entry of the container by its identifier and returns it. |
203
|
|
|
* |
204
|
|
|
* @param string $id Identifier of the entry to look for |
205
|
|
|
* |
206
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface No entry was found for **this** identifier. |
207
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface Error while retrieving the entry. |
208
|
|
|
* |
209
|
|
|
* @return mixed Entry. |
210
|
|
|
*/ |
211
|
|
|
public function get($id) |
212
|
|
|
{ |
213
|
|
|
return $this->provider->get($id); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Returns true if the container can return an entry for the given identifier. |
218
|
|
|
* Returns false otherwise. |
219
|
|
|
* |
220
|
|
|
* `has($id)` returning TRUE does not mean that `get($id)` will not throw an exception. |
221
|
|
|
* It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
222
|
|
|
* |
223
|
|
|
* @param string $id Identifier of the entry to look for. |
224
|
|
|
* |
225
|
|
|
* @return boolean TRUE if an entroy for the given identifier exists, else FALSE |
226
|
|
|
*/ |
227
|
|
|
public function has($id) |
228
|
|
|
{ |
229
|
|
|
return $this->provider->has($id); |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..