1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Vitaly Iegorov <[email protected]>. |
4
|
|
|
* on 07.08.16 at 13:04 |
5
|
|
|
*/ |
6
|
|
|
namespace samsonframework\container\resolver; |
7
|
|
|
|
8
|
|
|
use samsonframework\container\annotation\MethodInterface; |
9
|
|
|
use samsonframework\container\annotation\ParameterInterface; |
10
|
|
|
use samsonframework\container\metadata\ClassMetadata; |
11
|
|
|
use samsonframework\container\metadata\MethodMetadata; |
12
|
|
|
use samsonframework\container\metadata\ParameterMetadata; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class method annotation resolver. |
16
|
|
|
*/ |
17
|
|
|
class AnnotationMethodResolver extends AbstractAnnotationResolver implements AnnotationResolverInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritDoc} |
21
|
|
|
*/ |
22
|
|
|
public function resolve(\ReflectionClass $classData, ClassMetadata $classMetadata) |
23
|
|
|
{ |
24
|
|
|
/** @var \ReflectionMethod $method */ |
25
|
|
|
foreach ($classData->getMethods() as $method) { |
26
|
|
|
$this->resolveMethodAnnotations($method, $classMetadata); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
return $this->classMetadata; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Resolve class method annotations. |
34
|
|
|
* |
35
|
|
|
* @param \ReflectionMethod $method |
36
|
|
|
* @param ClassMetadata $classMetadata |
37
|
|
|
*/ |
38
|
|
|
protected function resolveMethodAnnotations(\ReflectionMethod $method, ClassMetadata $classMetadata) |
39
|
|
|
{ |
40
|
|
|
// Create method metadata instance |
41
|
|
|
$methodMetadata = new MethodMetadata($classMetadata); |
42
|
|
|
$methodMetadata->name = $method->getName(); |
|
|
|
|
43
|
|
|
$methodMetadata->modifiers = $method->getModifiers(); |
44
|
|
|
|
45
|
|
|
/** @var \ReflectionParameter $parameter */ |
46
|
|
|
$parameterMetadata = new ParameterMetadata($classMetadata, $methodMetadata); |
47
|
|
|
foreach ($method->getParameters() as $parameter) { |
48
|
|
|
$parameterMetadata = clone $parameterMetadata; |
49
|
|
|
$parameterMetadata->name = $parameter->getName(); |
|
|
|
|
50
|
|
|
$parameterMetadata->typeHint = $parameter->getType()->__toString(); |
51
|
|
|
$methodMetadata->parametersMetadata[$parameterMetadata->name] = $parameterMetadata; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** @var MethodInterface|ParameterInterface $annotation */ |
55
|
|
|
foreach ($this->reader->getMethodAnnotations($method) as $annotation) { |
56
|
|
|
if ($annotation instanceof MethodInterface) { |
57
|
|
|
$annotation->toMethodMetadata($methodMetadata); |
58
|
|
|
} |
59
|
|
|
if ($annotation instanceof ParameterInterface) { |
60
|
|
|
$annotation->toParameterMetadata(new ParameterMetadata($methodMetadata)); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$classMetadata->methodsMetadata[$method->getName()] = $methodMetadata; |
|
|
|
|
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|