Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\DependencyInjection;
|
Chris@0
|
13
|
Chris@0
|
14 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
Chris@0
|
15 use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException;
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Definition represents a service definition.
|
Chris@0
|
19 *
|
Chris@0
|
20 * @author Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
21 */
|
Chris@0
|
22 class Definition
|
Chris@0
|
23 {
|
Chris@0
|
24 private $class;
|
Chris@0
|
25 private $file;
|
Chris@0
|
26 private $factory;
|
Chris@0
|
27 private $shared = true;
|
Chris@0
|
28 private $deprecated = false;
|
Chris@12
|
29 private $deprecationTemplate;
|
Chris@0
|
30 private $properties = array();
|
Chris@0
|
31 private $calls = array();
|
Chris@0
|
32 private $configurator;
|
Chris@0
|
33 private $tags = array();
|
Chris@0
|
34 private $public = true;
|
Chris@0
|
35 private $synthetic = false;
|
Chris@0
|
36 private $abstract = false;
|
Chris@0
|
37 private $lazy = false;
|
Chris@0
|
38 private $decoratedService;
|
Chris@0
|
39 private $autowired = false;
|
Chris@0
|
40 private $autowiringTypes = array();
|
Chris@0
|
41
|
Chris@12
|
42 private static $defaultDeprecationTemplate = 'The "%service_id%" service is deprecated. You should stop using it, as it will soon be removed.';
|
Chris@12
|
43
|
Chris@0
|
44 protected $arguments;
|
Chris@0
|
45
|
Chris@0
|
46 /**
|
Chris@0
|
47 * @param string|null $class The service class
|
Chris@0
|
48 * @param array $arguments An array of arguments to pass to the service constructor
|
Chris@0
|
49 */
|
Chris@0
|
50 public function __construct($class = null, array $arguments = array())
|
Chris@0
|
51 {
|
Chris@0
|
52 $this->class = $class;
|
Chris@0
|
53 $this->arguments = $arguments;
|
Chris@0
|
54 }
|
Chris@0
|
55
|
Chris@0
|
56 /**
|
Chris@0
|
57 * Sets a factory.
|
Chris@0
|
58 *
|
Chris@0
|
59 * @param string|array $factory A PHP function or an array containing a class/Reference and a method to call
|
Chris@0
|
60 *
|
Chris@0
|
61 * @return $this
|
Chris@0
|
62 */
|
Chris@0
|
63 public function setFactory($factory)
|
Chris@0
|
64 {
|
Chris@0
|
65 if (is_string($factory) && strpos($factory, '::') !== false) {
|
Chris@0
|
66 $factory = explode('::', $factory, 2);
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 $this->factory = $factory;
|
Chris@0
|
70
|
Chris@0
|
71 return $this;
|
Chris@0
|
72 }
|
Chris@0
|
73
|
Chris@0
|
74 /**
|
Chris@0
|
75 * Gets the factory.
|
Chris@0
|
76 *
|
Chris@0
|
77 * @return string|array The PHP function or an array containing a class/Reference and a method to call
|
Chris@0
|
78 */
|
Chris@0
|
79 public function getFactory()
|
Chris@0
|
80 {
|
Chris@0
|
81 return $this->factory;
|
Chris@0
|
82 }
|
Chris@0
|
83
|
Chris@0
|
84 /**
|
Chris@0
|
85 * Sets the service that this service is decorating.
|
Chris@0
|
86 *
|
Chris@0
|
87 * @param null|string $id The decorated service id, use null to remove decoration
|
Chris@0
|
88 * @param null|string $renamedId The new decorated service id
|
Chris@0
|
89 * @param int $priority The priority of decoration
|
Chris@0
|
90 *
|
Chris@0
|
91 * @return $this
|
Chris@0
|
92 *
|
Chris@0
|
93 * @throws InvalidArgumentException In case the decorated service id and the new decorated service id are equals.
|
Chris@0
|
94 */
|
Chris@0
|
95 public function setDecoratedService($id, $renamedId = null, $priority = 0)
|
Chris@0
|
96 {
|
Chris@0
|
97 if ($renamedId && $id == $renamedId) {
|
Chris@0
|
98 throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id));
|
Chris@0
|
99 }
|
Chris@0
|
100
|
Chris@0
|
101 if (null === $id) {
|
Chris@0
|
102 $this->decoratedService = null;
|
Chris@0
|
103 } else {
|
Chris@0
|
104 $this->decoratedService = array($id, $renamedId, (int) $priority);
|
Chris@0
|
105 }
|
Chris@0
|
106
|
Chris@0
|
107 return $this;
|
Chris@0
|
108 }
|
Chris@0
|
109
|
Chris@0
|
110 /**
|
Chris@0
|
111 * Gets the service that this service is decorating.
|
Chris@0
|
112 *
|
Chris@0
|
113 * @return null|array An array composed of the decorated service id, the new id for it and the priority of decoration, null if no service is decorated
|
Chris@0
|
114 */
|
Chris@0
|
115 public function getDecoratedService()
|
Chris@0
|
116 {
|
Chris@0
|
117 return $this->decoratedService;
|
Chris@0
|
118 }
|
Chris@0
|
119
|
Chris@0
|
120 /**
|
Chris@0
|
121 * Sets the service class.
|
Chris@0
|
122 *
|
Chris@0
|
123 * @param string $class The service class
|
Chris@0
|
124 *
|
Chris@0
|
125 * @return $this
|
Chris@0
|
126 */
|
Chris@0
|
127 public function setClass($class)
|
Chris@0
|
128 {
|
Chris@0
|
129 $this->class = $class;
|
Chris@0
|
130
|
Chris@0
|
131 return $this;
|
Chris@0
|
132 }
|
Chris@0
|
133
|
Chris@0
|
134 /**
|
Chris@0
|
135 * Gets the service class.
|
Chris@0
|
136 *
|
Chris@0
|
137 * @return string|null The service class
|
Chris@0
|
138 */
|
Chris@0
|
139 public function getClass()
|
Chris@0
|
140 {
|
Chris@0
|
141 return $this->class;
|
Chris@0
|
142 }
|
Chris@0
|
143
|
Chris@0
|
144 /**
|
Chris@0
|
145 * Sets the arguments to pass to the service constructor/factory method.
|
Chris@0
|
146 *
|
Chris@0
|
147 * @param array $arguments An array of arguments
|
Chris@0
|
148 *
|
Chris@0
|
149 * @return $this
|
Chris@0
|
150 */
|
Chris@0
|
151 public function setArguments(array $arguments)
|
Chris@0
|
152 {
|
Chris@0
|
153 $this->arguments = $arguments;
|
Chris@0
|
154
|
Chris@0
|
155 return $this;
|
Chris@0
|
156 }
|
Chris@0
|
157
|
Chris@0
|
158 public function setProperties(array $properties)
|
Chris@0
|
159 {
|
Chris@0
|
160 $this->properties = $properties;
|
Chris@0
|
161
|
Chris@0
|
162 return $this;
|
Chris@0
|
163 }
|
Chris@0
|
164
|
Chris@0
|
165 public function getProperties()
|
Chris@0
|
166 {
|
Chris@0
|
167 return $this->properties;
|
Chris@0
|
168 }
|
Chris@0
|
169
|
Chris@0
|
170 public function setProperty($name, $value)
|
Chris@0
|
171 {
|
Chris@0
|
172 $this->properties[$name] = $value;
|
Chris@0
|
173
|
Chris@0
|
174 return $this;
|
Chris@0
|
175 }
|
Chris@0
|
176
|
Chris@0
|
177 /**
|
Chris@0
|
178 * Adds an argument to pass to the service constructor/factory method.
|
Chris@0
|
179 *
|
Chris@0
|
180 * @param mixed $argument An argument
|
Chris@0
|
181 *
|
Chris@0
|
182 * @return $this
|
Chris@0
|
183 */
|
Chris@0
|
184 public function addArgument($argument)
|
Chris@0
|
185 {
|
Chris@0
|
186 $this->arguments[] = $argument;
|
Chris@0
|
187
|
Chris@0
|
188 return $this;
|
Chris@0
|
189 }
|
Chris@0
|
190
|
Chris@0
|
191 /**
|
Chris@0
|
192 * Sets a specific argument.
|
Chris@0
|
193 *
|
Chris@0
|
194 * @param int $index
|
Chris@0
|
195 * @param mixed $argument
|
Chris@0
|
196 *
|
Chris@0
|
197 * @return $this
|
Chris@0
|
198 *
|
Chris@0
|
199 * @throws OutOfBoundsException When the replaced argument does not exist
|
Chris@0
|
200 */
|
Chris@0
|
201 public function replaceArgument($index, $argument)
|
Chris@0
|
202 {
|
Chris@0
|
203 if (0 === count($this->arguments)) {
|
Chris@0
|
204 throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.');
|
Chris@0
|
205 }
|
Chris@0
|
206
|
Chris@0
|
207 if ($index < 0 || $index > count($this->arguments) - 1) {
|
Chris@0
|
208 throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
|
Chris@0
|
209 }
|
Chris@0
|
210
|
Chris@0
|
211 $this->arguments[$index] = $argument;
|
Chris@0
|
212
|
Chris@0
|
213 return $this;
|
Chris@0
|
214 }
|
Chris@0
|
215
|
Chris@0
|
216 /**
|
Chris@0
|
217 * Gets the arguments to pass to the service constructor/factory method.
|
Chris@0
|
218 *
|
Chris@0
|
219 * @return array The array of arguments
|
Chris@0
|
220 */
|
Chris@0
|
221 public function getArguments()
|
Chris@0
|
222 {
|
Chris@0
|
223 return $this->arguments;
|
Chris@0
|
224 }
|
Chris@0
|
225
|
Chris@0
|
226 /**
|
Chris@0
|
227 * Gets an argument to pass to the service constructor/factory method.
|
Chris@0
|
228 *
|
Chris@0
|
229 * @param int $index
|
Chris@0
|
230 *
|
Chris@0
|
231 * @return mixed The argument value
|
Chris@0
|
232 *
|
Chris@0
|
233 * @throws OutOfBoundsException When the argument does not exist
|
Chris@0
|
234 */
|
Chris@0
|
235 public function getArgument($index)
|
Chris@0
|
236 {
|
Chris@0
|
237 if ($index < 0 || $index > count($this->arguments) - 1) {
|
Chris@0
|
238 throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1));
|
Chris@0
|
239 }
|
Chris@0
|
240
|
Chris@0
|
241 return $this->arguments[$index];
|
Chris@0
|
242 }
|
Chris@0
|
243
|
Chris@0
|
244 /**
|
Chris@0
|
245 * Sets the methods to call after service initialization.
|
Chris@0
|
246 *
|
Chris@0
|
247 * @param array $calls An array of method calls
|
Chris@0
|
248 *
|
Chris@0
|
249 * @return $this
|
Chris@0
|
250 */
|
Chris@0
|
251 public function setMethodCalls(array $calls = array())
|
Chris@0
|
252 {
|
Chris@0
|
253 $this->calls = array();
|
Chris@0
|
254 foreach ($calls as $call) {
|
Chris@0
|
255 $this->addMethodCall($call[0], $call[1]);
|
Chris@0
|
256 }
|
Chris@0
|
257
|
Chris@0
|
258 return $this;
|
Chris@0
|
259 }
|
Chris@0
|
260
|
Chris@0
|
261 /**
|
Chris@0
|
262 * Adds a method to call after service initialization.
|
Chris@0
|
263 *
|
Chris@0
|
264 * @param string $method The method name to call
|
Chris@0
|
265 * @param array $arguments An array of arguments to pass to the method call
|
Chris@0
|
266 *
|
Chris@0
|
267 * @return $this
|
Chris@0
|
268 *
|
Chris@0
|
269 * @throws InvalidArgumentException on empty $method param
|
Chris@0
|
270 */
|
Chris@0
|
271 public function addMethodCall($method, array $arguments = array())
|
Chris@0
|
272 {
|
Chris@0
|
273 if (empty($method)) {
|
Chris@0
|
274 throw new InvalidArgumentException('Method name cannot be empty.');
|
Chris@0
|
275 }
|
Chris@0
|
276 $this->calls[] = array($method, $arguments);
|
Chris@0
|
277
|
Chris@0
|
278 return $this;
|
Chris@0
|
279 }
|
Chris@0
|
280
|
Chris@0
|
281 /**
|
Chris@0
|
282 * Removes a method to call after service initialization.
|
Chris@0
|
283 *
|
Chris@0
|
284 * @param string $method The method name to remove
|
Chris@0
|
285 *
|
Chris@0
|
286 * @return $this
|
Chris@0
|
287 */
|
Chris@0
|
288 public function removeMethodCall($method)
|
Chris@0
|
289 {
|
Chris@0
|
290 foreach ($this->calls as $i => $call) {
|
Chris@0
|
291 if ($call[0] === $method) {
|
Chris@0
|
292 unset($this->calls[$i]);
|
Chris@0
|
293 break;
|
Chris@0
|
294 }
|
Chris@0
|
295 }
|
Chris@0
|
296
|
Chris@0
|
297 return $this;
|
Chris@0
|
298 }
|
Chris@0
|
299
|
Chris@0
|
300 /**
|
Chris@0
|
301 * Check if the current definition has a given method to call after service initialization.
|
Chris@0
|
302 *
|
Chris@0
|
303 * @param string $method The method name to search for
|
Chris@0
|
304 *
|
Chris@0
|
305 * @return bool
|
Chris@0
|
306 */
|
Chris@0
|
307 public function hasMethodCall($method)
|
Chris@0
|
308 {
|
Chris@0
|
309 foreach ($this->calls as $call) {
|
Chris@0
|
310 if ($call[0] === $method) {
|
Chris@0
|
311 return true;
|
Chris@0
|
312 }
|
Chris@0
|
313 }
|
Chris@0
|
314
|
Chris@0
|
315 return false;
|
Chris@0
|
316 }
|
Chris@0
|
317
|
Chris@0
|
318 /**
|
Chris@0
|
319 * Gets the methods to call after service initialization.
|
Chris@0
|
320 *
|
Chris@0
|
321 * @return array An array of method calls
|
Chris@0
|
322 */
|
Chris@0
|
323 public function getMethodCalls()
|
Chris@0
|
324 {
|
Chris@0
|
325 return $this->calls;
|
Chris@0
|
326 }
|
Chris@0
|
327
|
Chris@0
|
328 /**
|
Chris@0
|
329 * Sets tags for this definition.
|
Chris@0
|
330 *
|
Chris@0
|
331 * @param array $tags
|
Chris@0
|
332 *
|
Chris@0
|
333 * @return $this
|
Chris@0
|
334 */
|
Chris@0
|
335 public function setTags(array $tags)
|
Chris@0
|
336 {
|
Chris@0
|
337 $this->tags = $tags;
|
Chris@0
|
338
|
Chris@0
|
339 return $this;
|
Chris@0
|
340 }
|
Chris@0
|
341
|
Chris@0
|
342 /**
|
Chris@0
|
343 * Returns all tags.
|
Chris@0
|
344 *
|
Chris@0
|
345 * @return array An array of tags
|
Chris@0
|
346 */
|
Chris@0
|
347 public function getTags()
|
Chris@0
|
348 {
|
Chris@0
|
349 return $this->tags;
|
Chris@0
|
350 }
|
Chris@0
|
351
|
Chris@0
|
352 /**
|
Chris@0
|
353 * Gets a tag by name.
|
Chris@0
|
354 *
|
Chris@0
|
355 * @param string $name The tag name
|
Chris@0
|
356 *
|
Chris@0
|
357 * @return array An array of attributes
|
Chris@0
|
358 */
|
Chris@0
|
359 public function getTag($name)
|
Chris@0
|
360 {
|
Chris@0
|
361 return isset($this->tags[$name]) ? $this->tags[$name] : array();
|
Chris@0
|
362 }
|
Chris@0
|
363
|
Chris@0
|
364 /**
|
Chris@0
|
365 * Adds a tag for this definition.
|
Chris@0
|
366 *
|
Chris@0
|
367 * @param string $name The tag name
|
Chris@0
|
368 * @param array $attributes An array of attributes
|
Chris@0
|
369 *
|
Chris@0
|
370 * @return $this
|
Chris@0
|
371 */
|
Chris@0
|
372 public function addTag($name, array $attributes = array())
|
Chris@0
|
373 {
|
Chris@0
|
374 $this->tags[$name][] = $attributes;
|
Chris@0
|
375
|
Chris@0
|
376 return $this;
|
Chris@0
|
377 }
|
Chris@0
|
378
|
Chris@0
|
379 /**
|
Chris@0
|
380 * Whether this definition has a tag with the given name.
|
Chris@0
|
381 *
|
Chris@0
|
382 * @param string $name
|
Chris@0
|
383 *
|
Chris@0
|
384 * @return bool
|
Chris@0
|
385 */
|
Chris@0
|
386 public function hasTag($name)
|
Chris@0
|
387 {
|
Chris@0
|
388 return isset($this->tags[$name]);
|
Chris@0
|
389 }
|
Chris@0
|
390
|
Chris@0
|
391 /**
|
Chris@0
|
392 * Clears all tags for a given name.
|
Chris@0
|
393 *
|
Chris@0
|
394 * @param string $name The tag name
|
Chris@0
|
395 *
|
Chris@0
|
396 * @return $this
|
Chris@0
|
397 */
|
Chris@0
|
398 public function clearTag($name)
|
Chris@0
|
399 {
|
Chris@0
|
400 unset($this->tags[$name]);
|
Chris@0
|
401
|
Chris@0
|
402 return $this;
|
Chris@0
|
403 }
|
Chris@0
|
404
|
Chris@0
|
405 /**
|
Chris@0
|
406 * Clears the tags for this definition.
|
Chris@0
|
407 *
|
Chris@0
|
408 * @return $this
|
Chris@0
|
409 */
|
Chris@0
|
410 public function clearTags()
|
Chris@0
|
411 {
|
Chris@0
|
412 $this->tags = array();
|
Chris@0
|
413
|
Chris@0
|
414 return $this;
|
Chris@0
|
415 }
|
Chris@0
|
416
|
Chris@0
|
417 /**
|
Chris@0
|
418 * Sets a file to require before creating the service.
|
Chris@0
|
419 *
|
Chris@0
|
420 * @param string $file A full pathname to include
|
Chris@0
|
421 *
|
Chris@0
|
422 * @return $this
|
Chris@0
|
423 */
|
Chris@0
|
424 public function setFile($file)
|
Chris@0
|
425 {
|
Chris@0
|
426 $this->file = $file;
|
Chris@0
|
427
|
Chris@0
|
428 return $this;
|
Chris@0
|
429 }
|
Chris@0
|
430
|
Chris@0
|
431 /**
|
Chris@0
|
432 * Gets the file to require before creating the service.
|
Chris@0
|
433 *
|
Chris@0
|
434 * @return string|null The full pathname to include
|
Chris@0
|
435 */
|
Chris@0
|
436 public function getFile()
|
Chris@0
|
437 {
|
Chris@0
|
438 return $this->file;
|
Chris@0
|
439 }
|
Chris@0
|
440
|
Chris@0
|
441 /**
|
Chris@0
|
442 * Sets if the service must be shared or not.
|
Chris@0
|
443 *
|
Chris@0
|
444 * @param bool $shared Whether the service must be shared or not
|
Chris@0
|
445 *
|
Chris@0
|
446 * @return $this
|
Chris@0
|
447 */
|
Chris@0
|
448 public function setShared($shared)
|
Chris@0
|
449 {
|
Chris@0
|
450 $this->shared = (bool) $shared;
|
Chris@0
|
451
|
Chris@0
|
452 return $this;
|
Chris@0
|
453 }
|
Chris@0
|
454
|
Chris@0
|
455 /**
|
Chris@0
|
456 * Whether this service is shared.
|
Chris@0
|
457 *
|
Chris@0
|
458 * @return bool
|
Chris@0
|
459 */
|
Chris@0
|
460 public function isShared()
|
Chris@0
|
461 {
|
Chris@0
|
462 return $this->shared;
|
Chris@0
|
463 }
|
Chris@0
|
464
|
Chris@0
|
465 /**
|
Chris@0
|
466 * Sets the visibility of this service.
|
Chris@0
|
467 *
|
Chris@0
|
468 * @param bool $boolean
|
Chris@0
|
469 *
|
Chris@0
|
470 * @return $this
|
Chris@0
|
471 */
|
Chris@0
|
472 public function setPublic($boolean)
|
Chris@0
|
473 {
|
Chris@0
|
474 $this->public = (bool) $boolean;
|
Chris@0
|
475
|
Chris@0
|
476 return $this;
|
Chris@0
|
477 }
|
Chris@0
|
478
|
Chris@0
|
479 /**
|
Chris@0
|
480 * Whether this service is public facing.
|
Chris@0
|
481 *
|
Chris@0
|
482 * @return bool
|
Chris@0
|
483 */
|
Chris@0
|
484 public function isPublic()
|
Chris@0
|
485 {
|
Chris@0
|
486 return $this->public;
|
Chris@0
|
487 }
|
Chris@0
|
488
|
Chris@0
|
489 /**
|
Chris@0
|
490 * Sets the lazy flag of this service.
|
Chris@0
|
491 *
|
Chris@0
|
492 * @param bool $lazy
|
Chris@0
|
493 *
|
Chris@0
|
494 * @return $this
|
Chris@0
|
495 */
|
Chris@0
|
496 public function setLazy($lazy)
|
Chris@0
|
497 {
|
Chris@0
|
498 $this->lazy = (bool) $lazy;
|
Chris@0
|
499
|
Chris@0
|
500 return $this;
|
Chris@0
|
501 }
|
Chris@0
|
502
|
Chris@0
|
503 /**
|
Chris@0
|
504 * Whether this service is lazy.
|
Chris@0
|
505 *
|
Chris@0
|
506 * @return bool
|
Chris@0
|
507 */
|
Chris@0
|
508 public function isLazy()
|
Chris@0
|
509 {
|
Chris@0
|
510 return $this->lazy;
|
Chris@0
|
511 }
|
Chris@0
|
512
|
Chris@0
|
513 /**
|
Chris@0
|
514 * Sets whether this definition is synthetic, that is not constructed by the
|
Chris@0
|
515 * container, but dynamically injected.
|
Chris@0
|
516 *
|
Chris@0
|
517 * @param bool $boolean
|
Chris@0
|
518 *
|
Chris@0
|
519 * @return $this
|
Chris@0
|
520 */
|
Chris@0
|
521 public function setSynthetic($boolean)
|
Chris@0
|
522 {
|
Chris@0
|
523 $this->synthetic = (bool) $boolean;
|
Chris@0
|
524
|
Chris@0
|
525 return $this;
|
Chris@0
|
526 }
|
Chris@0
|
527
|
Chris@0
|
528 /**
|
Chris@0
|
529 * Whether this definition is synthetic, that is not constructed by the
|
Chris@0
|
530 * container, but dynamically injected.
|
Chris@0
|
531 *
|
Chris@0
|
532 * @return bool
|
Chris@0
|
533 */
|
Chris@0
|
534 public function isSynthetic()
|
Chris@0
|
535 {
|
Chris@0
|
536 return $this->synthetic;
|
Chris@0
|
537 }
|
Chris@0
|
538
|
Chris@0
|
539 /**
|
Chris@0
|
540 * Whether this definition is abstract, that means it merely serves as a
|
Chris@0
|
541 * template for other definitions.
|
Chris@0
|
542 *
|
Chris@0
|
543 * @param bool $boolean
|
Chris@0
|
544 *
|
Chris@0
|
545 * @return $this
|
Chris@0
|
546 */
|
Chris@0
|
547 public function setAbstract($boolean)
|
Chris@0
|
548 {
|
Chris@0
|
549 $this->abstract = (bool) $boolean;
|
Chris@0
|
550
|
Chris@0
|
551 return $this;
|
Chris@0
|
552 }
|
Chris@0
|
553
|
Chris@0
|
554 /**
|
Chris@0
|
555 * Whether this definition is abstract, that means it merely serves as a
|
Chris@0
|
556 * template for other definitions.
|
Chris@0
|
557 *
|
Chris@0
|
558 * @return bool
|
Chris@0
|
559 */
|
Chris@0
|
560 public function isAbstract()
|
Chris@0
|
561 {
|
Chris@0
|
562 return $this->abstract;
|
Chris@0
|
563 }
|
Chris@0
|
564
|
Chris@0
|
565 /**
|
Chris@0
|
566 * Whether this definition is deprecated, that means it should not be called
|
Chris@0
|
567 * anymore.
|
Chris@0
|
568 *
|
Chris@0
|
569 * @param bool $status
|
Chris@0
|
570 * @param string $template Template message to use if the definition is deprecated
|
Chris@0
|
571 *
|
Chris@0
|
572 * @return $this
|
Chris@0
|
573 *
|
Chris@0
|
574 * @throws InvalidArgumentException When the message template is invalid.
|
Chris@0
|
575 */
|
Chris@0
|
576 public function setDeprecated($status = true, $template = null)
|
Chris@0
|
577 {
|
Chris@0
|
578 if (null !== $template) {
|
Chris@0
|
579 if (preg_match('#[\r\n]|\*/#', $template)) {
|
Chris@0
|
580 throw new InvalidArgumentException('Invalid characters found in deprecation template.');
|
Chris@0
|
581 }
|
Chris@0
|
582
|
Chris@0
|
583 if (false === strpos($template, '%service_id%')) {
|
Chris@0
|
584 throw new InvalidArgumentException('The deprecation template must contain the "%service_id%" placeholder.');
|
Chris@0
|
585 }
|
Chris@0
|
586
|
Chris@0
|
587 $this->deprecationTemplate = $template;
|
Chris@0
|
588 }
|
Chris@0
|
589
|
Chris@0
|
590 $this->deprecated = (bool) $status;
|
Chris@0
|
591
|
Chris@0
|
592 return $this;
|
Chris@0
|
593 }
|
Chris@0
|
594
|
Chris@0
|
595 /**
|
Chris@0
|
596 * Whether this definition is deprecated, that means it should not be called
|
Chris@0
|
597 * anymore.
|
Chris@0
|
598 *
|
Chris@0
|
599 * @return bool
|
Chris@0
|
600 */
|
Chris@0
|
601 public function isDeprecated()
|
Chris@0
|
602 {
|
Chris@0
|
603 return $this->deprecated;
|
Chris@0
|
604 }
|
Chris@0
|
605
|
Chris@0
|
606 /**
|
Chris@0
|
607 * Message to use if this definition is deprecated.
|
Chris@0
|
608 *
|
Chris@0
|
609 * @param string $id Service id relying on this definition
|
Chris@0
|
610 *
|
Chris@0
|
611 * @return string
|
Chris@0
|
612 */
|
Chris@0
|
613 public function getDeprecationMessage($id)
|
Chris@0
|
614 {
|
Chris@12
|
615 return str_replace('%service_id%', $id, $this->deprecationTemplate ?: self::$defaultDeprecationTemplate);
|
Chris@0
|
616 }
|
Chris@0
|
617
|
Chris@0
|
618 /**
|
Chris@0
|
619 * Sets a configurator to call after the service is fully initialized.
|
Chris@0
|
620 *
|
Chris@0
|
621 * @param string|array $configurator A PHP callable
|
Chris@0
|
622 *
|
Chris@0
|
623 * @return $this
|
Chris@0
|
624 */
|
Chris@0
|
625 public function setConfigurator($configurator)
|
Chris@0
|
626 {
|
Chris@0
|
627 if (is_string($configurator) && strpos($configurator, '::') !== false) {
|
Chris@0
|
628 $configurator = explode('::', $configurator, 2);
|
Chris@0
|
629 }
|
Chris@0
|
630
|
Chris@0
|
631 $this->configurator = $configurator;
|
Chris@0
|
632
|
Chris@0
|
633 return $this;
|
Chris@0
|
634 }
|
Chris@0
|
635
|
Chris@0
|
636 /**
|
Chris@0
|
637 * Gets the configurator to call after the service is fully initialized.
|
Chris@0
|
638 *
|
Chris@0
|
639 * @return callable|null The PHP callable to call
|
Chris@0
|
640 */
|
Chris@0
|
641 public function getConfigurator()
|
Chris@0
|
642 {
|
Chris@0
|
643 return $this->configurator;
|
Chris@0
|
644 }
|
Chris@0
|
645
|
Chris@0
|
646 /**
|
Chris@0
|
647 * Sets types that will default to this definition.
|
Chris@0
|
648 *
|
Chris@0
|
649 * @param string[] $types
|
Chris@0
|
650 *
|
Chris@0
|
651 * @return $this
|
Chris@0
|
652 */
|
Chris@0
|
653 public function setAutowiringTypes(array $types)
|
Chris@0
|
654 {
|
Chris@0
|
655 $this->autowiringTypes = array();
|
Chris@0
|
656
|
Chris@0
|
657 foreach ($types as $type) {
|
Chris@0
|
658 $this->autowiringTypes[$type] = true;
|
Chris@0
|
659 }
|
Chris@0
|
660
|
Chris@0
|
661 return $this;
|
Chris@0
|
662 }
|
Chris@0
|
663
|
Chris@0
|
664 /**
|
Chris@0
|
665 * Is the definition autowired?
|
Chris@0
|
666 *
|
Chris@0
|
667 * @return bool
|
Chris@0
|
668 */
|
Chris@0
|
669 public function isAutowired()
|
Chris@0
|
670 {
|
Chris@0
|
671 return $this->autowired;
|
Chris@0
|
672 }
|
Chris@0
|
673
|
Chris@0
|
674 /**
|
Chris@0
|
675 * Sets autowired.
|
Chris@0
|
676 *
|
Chris@0
|
677 * @param bool $autowired
|
Chris@0
|
678 *
|
Chris@0
|
679 * @return $this
|
Chris@0
|
680 */
|
Chris@0
|
681 public function setAutowired($autowired)
|
Chris@0
|
682 {
|
Chris@0
|
683 $this->autowired = $autowired;
|
Chris@0
|
684
|
Chris@0
|
685 return $this;
|
Chris@0
|
686 }
|
Chris@0
|
687
|
Chris@0
|
688 /**
|
Chris@0
|
689 * Gets autowiring types that will default to this definition.
|
Chris@0
|
690 *
|
Chris@0
|
691 * @return string[]
|
Chris@0
|
692 */
|
Chris@0
|
693 public function getAutowiringTypes()
|
Chris@0
|
694 {
|
Chris@0
|
695 return array_keys($this->autowiringTypes);
|
Chris@0
|
696 }
|
Chris@0
|
697
|
Chris@0
|
698 /**
|
Chris@0
|
699 * Adds a type that will default to this definition.
|
Chris@0
|
700 *
|
Chris@0
|
701 * @param string $type
|
Chris@0
|
702 *
|
Chris@0
|
703 * @return $this
|
Chris@0
|
704 */
|
Chris@0
|
705 public function addAutowiringType($type)
|
Chris@0
|
706 {
|
Chris@0
|
707 $this->autowiringTypes[$type] = true;
|
Chris@0
|
708
|
Chris@0
|
709 return $this;
|
Chris@0
|
710 }
|
Chris@0
|
711
|
Chris@0
|
712 /**
|
Chris@0
|
713 * Removes a type.
|
Chris@0
|
714 *
|
Chris@0
|
715 * @param string $type
|
Chris@0
|
716 *
|
Chris@0
|
717 * @return $this
|
Chris@0
|
718 */
|
Chris@0
|
719 public function removeAutowiringType($type)
|
Chris@0
|
720 {
|
Chris@0
|
721 unset($this->autowiringTypes[$type]);
|
Chris@0
|
722
|
Chris@0
|
723 return $this;
|
Chris@0
|
724 }
|
Chris@0
|
725
|
Chris@0
|
726 /**
|
Chris@0
|
727 * Will this definition default for the given type?
|
Chris@0
|
728 *
|
Chris@0
|
729 * @param string $type
|
Chris@0
|
730 *
|
Chris@0
|
731 * @return bool
|
Chris@0
|
732 */
|
Chris@0
|
733 public function hasAutowiringType($type)
|
Chris@0
|
734 {
|
Chris@0
|
735 return isset($this->autowiringTypes[$type]);
|
Chris@0
|
736 }
|
Chris@0
|
737 }
|