|
0
|
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\DependencyInjection; |
|
|
13 |
|
|
|
14 |
/** |
|
|
15 |
* Reference represents a service reference. |
|
|
16 |
* |
|
|
17 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
18 |
* |
|
|
19 |
* @api |
|
|
20 |
*/ |
|
|
21 |
class Reference |
|
|
22 |
{ |
|
|
23 |
private $id; |
|
|
24 |
private $invalidBehavior; |
|
|
25 |
private $strict; |
|
|
26 |
|
|
|
27 |
/** |
|
|
28 |
* Constructor. |
|
|
29 |
* |
|
|
30 |
* @param string $id The service identifier |
|
|
31 |
* @param int $invalidBehavior The behavior when the service does not exist |
|
|
32 |
* @param Boolean $strict Sets how this reference is validated |
|
|
33 |
* |
|
|
34 |
* @see Container |
|
|
35 |
*/ |
|
|
36 |
public function __construct($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $strict = true) |
|
|
37 |
{ |
|
|
38 |
$this->id = $id; |
|
|
39 |
$this->invalidBehavior = $invalidBehavior; |
|
|
40 |
$this->strict = $strict; |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
/** |
|
|
44 |
* __toString. |
|
|
45 |
* |
|
|
46 |
* @return string The service identifier |
|
|
47 |
*/ |
|
|
48 |
public function __toString() |
|
|
49 |
{ |
|
|
50 |
return (string) $this->id; |
|
|
51 |
} |
|
|
52 |
|
|
|
53 |
/** |
|
|
54 |
* Returns the behavior to be used when the service does not exist. |
|
|
55 |
* |
|
|
56 |
* @return int |
|
|
57 |
*/ |
|
|
58 |
public function getInvalidBehavior() |
|
|
59 |
{ |
|
|
60 |
return $this->invalidBehavior; |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
/** |
|
|
64 |
* Returns true when this Reference is strict |
|
|
65 |
* |
|
|
66 |
* @return Boolean |
|
|
67 |
*/ |
|
|
68 |
public function isStrict() |
|
|
69 |
{ |
|
|
70 |
return $this->strict; |
|
|
71 |
} |
|
|
72 |
} |