1 | <?php |
||
9 | final class Argument |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $index; |
||
15 | |||
16 | /** |
||
17 | * @var bool |
||
18 | */ |
||
19 | private $isDefaultAvailable; |
||
20 | |||
21 | /** |
||
22 | * @var |
||
23 | */ |
||
24 | private $default; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $meta; |
||
30 | |||
31 | /** |
||
32 | * @var \ReflectionParameter |
||
33 | */ |
||
34 | private $reflection; |
||
35 | |||
36 | 61 | public function __construct(\ReflectionParameter $parameter, $name) |
|
37 | { |
||
38 | 61 | $interface = $this->getTypeHint($parameter); |
|
39 | 61 | $interface = ($interface === 'array') ? '' : $interface; // hhvm |
|
40 | 61 | $isOptional = $parameter->isOptional(); |
|
41 | 61 | $this->isDefaultAvailable = $parameter->isDefaultValueAvailable() || $isOptional; |
|
42 | 61 | if ($isOptional) { |
|
43 | 12 | $this->default = null; |
|
44 | } |
||
45 | 61 | $this->setDefaultValue($parameter); |
|
46 | 61 | $this->index = $interface . '-' . $name; |
|
47 | 61 | $this->reflection = $parameter; |
|
48 | 61 | $this->meta = sprintf( |
|
49 | 61 | "dependency '%s' with name '%s' used in %s:%d ($%s)", |
|
50 | $interface, |
||
51 | $name, |
||
52 | 61 | $this->reflection->getDeclaringFunction()->getFileName(), |
|
53 | 61 | $this->reflection->getDeclaringFunction()->getStartLine(), |
|
54 | 61 | $parameter->getName() |
|
55 | ); |
||
56 | 61 | } |
|
57 | |||
58 | /** |
||
59 | * Return reflection |
||
60 | * |
||
61 | * @return \ReflectionParameter |
||
62 | */ |
||
63 | 34 | public function get() |
|
67 | |||
68 | /** |
||
69 | * @param \ReflectionParameter $parameter |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 61 | private function getTypeHint(\ReflectionParameter $parameter) |
|
83 | |||
84 | /** |
||
85 | * @return string |
||
86 | */ |
||
87 | 36 | public function __toString() |
|
91 | |||
92 | /** |
||
93 | * @return bool |
||
94 | */ |
||
95 | 13 | public function isDefaultAvailable() |
|
99 | |||
100 | /** |
||
101 | * @return mixed |
||
102 | */ |
||
103 | 7 | public function getDefaultValue() |
|
107 | |||
108 | 7 | public function getMeta() |
|
112 | |||
113 | 61 | private function setDefaultValue(\ReflectionParameter $parameter) |
|
125 | } |
||
126 |