|
1
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
2
|
|
|
/**
|
|
3
|
|
|
* Created by Ruslan Molodyko.
|
|
4
|
|
|
* Date: 10.09.2016
|
|
5
|
|
|
* Time: 17:48
|
|
6
|
|
|
*/
|
|
7
|
|
|
namespace samsonframework\container\definition\analyzer\annotation;
|
|
8
|
|
|
|
|
9
|
|
|
use samsonframework\container\definition\analyzer\DefinitionAnalyzer;
|
|
10
|
|
|
use samsonframework\container\definition\analyzer\MethodAnalyzerInterface;
|
|
11
|
|
|
use samsonframework\container\definition\ClassDefinition;
|
|
12
|
|
|
use samsonframework\container\definition\exception\MethodDefinitionAlreadyExistsException;
|
|
13
|
|
|
|
|
14
|
|
|
/**
|
|
15
|
|
|
* Class AnnotationMethodAnalyzer
|
|
16
|
|
|
*
|
|
17
|
|
|
* @author Ruslan Molodyko <[email protected]>
|
|
18
|
|
|
*/
|
|
19
|
|
|
class AnnotationMethodAnalyzer extends AbstractAnnotationAnalyzer implements MethodAnalyzerInterface
|
|
20
|
|
|
{
|
|
21
|
|
|
/**
|
|
22
|
|
|
* {@inheritdoc}
|
|
23
|
|
|
* @throws MethodDefinitionAlreadyExistsException
|
|
24
|
|
|
*/
|
|
25
|
2 |
|
public function analyze(
|
|
26
|
|
|
DefinitionAnalyzer $analyzer,
|
|
27
|
|
|
ClassDefinition $classDefinition,
|
|
28
|
|
|
\ReflectionMethod $reflectionMethod
|
|
29
|
|
|
) {
|
|
30
|
2 |
|
$methodName = $reflectionMethod->getName();
|
|
|
|
|
|
|
31
|
|
|
// Resolve annotations
|
|
32
|
2 |
|
$annotations = $this->reader->getMethodAnnotations($reflectionMethod);
|
|
33
|
|
|
// Create method definition if annotation is exists
|
|
34
|
2 |
|
if (count($annotations)) {
|
|
35
|
|
|
// Define method if not exists
|
|
36
|
2 |
|
if (!$classDefinition->hasMethod($methodName)) {
|
|
37
|
2 |
|
$classDefinition->defineMethod($methodName);
|
|
38
|
|
|
}
|
|
39
|
|
|
// Exec method annotations
|
|
40
|
2 |
|
foreach ($annotations as $annotation) {
|
|
41
|
2 |
|
if ($annotation instanceof ResolveMethodInterface) {
|
|
42
|
2 |
|
$annotation->resolveMethod($analyzer, $classDefinition, $reflectionMethod);
|
|
43
|
|
|
}
|
|
44
|
|
|
}
|
|
45
|
|
|
}
|
|
46
|
2 |
|
}
|
|
47
|
|
|
}
|
|
48
|
|
|
|