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\metadata\ClassMetadata; |
10
|
|
|
use samsonframework\container\metadata\MethodMetadata; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class method annotation resolver. |
14
|
|
|
*/ |
15
|
|
|
class AnnotationMethodResolver extends AbstractAnnotationResolver implements AnnotationResolverInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* {@inheritDoc} |
19
|
|
|
*/ |
20
|
|
|
public function resolve(\ReflectionClass $classData, ClassMetadata $classMetadata) |
21
|
|
|
{ |
22
|
|
|
/** @var \ReflectionMethod $method */ |
23
|
|
|
foreach ($classData->getMethods() as $method) { |
24
|
|
|
$this->resolveMethodAnnotations($method, $classMetadata); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return $this->classMetadata; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Resolve class method annotations. |
32
|
|
|
* |
33
|
|
|
* @param \ReflectionMethod $method |
34
|
|
|
* @param ClassMetadata $classMetadata |
35
|
|
|
*/ |
36
|
|
|
protected function resolveMethodAnnotations(\ReflectionMethod $method, ClassMetadata $classMetadata) |
37
|
|
|
{ |
38
|
|
|
// Create method metadata instance |
39
|
|
|
$methodMetadata = new MethodMetadata(); |
40
|
|
|
$methodMetadata->name = $method->getName(); |
|
|
|
|
41
|
|
|
$methodMetadata->modifiers = $method->getModifiers(); |
42
|
|
|
$methodMetadata->parameters = $method->getParameters(); |
43
|
|
|
|
44
|
|
|
/** @var MethodInterface $annotation */ |
45
|
|
|
foreach ($this->reader->getMethodAnnotations($method) as $annotation) { |
46
|
|
|
if ($annotation instanceof MethodInterface) { |
47
|
|
|
$methodMetadata->options[] = $annotation->toMethodMetadata($methodMetadata); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$classMetadata->methodsMetadata[$method->getName()] = $methodMetadata; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|