1 | <?php |
||
14 | final class AssistedInterceptor implements MethodInterceptor |
||
15 | { |
||
16 | /** |
||
17 | * @var InjectorInterface |
||
18 | */ |
||
19 | private $injector; |
||
20 | |||
21 | 3 | public function __construct(InjectorInterface $injector) |
|
25 | |||
26 | /** |
||
27 | * Intercepts any method and injects instances of the missing arguments |
||
28 | * when they are type hinted |
||
29 | */ |
||
30 | 3 | public function invoke(MethodInvocation $invocation) |
|
31 | { |
||
32 | 3 | $method = $invocation->getMethod(); |
|
33 | 3 | $assisted = $method->getAnnotation('Ray\Di\Di\Assisted'); |
|
34 | /* @var \Ray\Di\Di\Assisted $assisted */ |
||
35 | 3 | $parameters = $method->getParameters(); |
|
36 | 3 | $arguments = $invocation->getArguments()->getArrayCopy(); |
|
37 | 3 | if ($assisted instanceof Assisted && $method instanceof ReflectionMethod) { |
|
38 | 3 | $arguments = $this->injectAssistedParameters($method, $assisted, $parameters, $arguments); |
|
39 | } |
||
40 | 3 | $invocation->getArguments()->exchangeArray($arguments); |
|
41 | |||
42 | 3 | return $invocation->proceed(); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param ReflectionMethod $method |
||
47 | * @param \ReflectionParameter $parameter |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | 3 | private function getName(ReflectionMethod $method, \ReflectionParameter $parameter) |
|
65 | |||
66 | /** |
||
67 | * @param ReflectionMethod $method |
||
68 | * @param Assisted $assisted |
||
69 | * @param \ReflectionParameter[] $parameters |
||
70 | * @param array $arguments |
||
71 | * |
||
72 | * @return array |
||
73 | * |
||
74 | * @internal param int $cntArgs |
||
75 | */ |
||
76 | 3 | public function injectAssistedParameters(ReflectionMethod $method, Assisted $assisted, array $parameters, array $arguments) |
|
90 | } |
||
91 |