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