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\PropertyAnalyzerInterface;
|
11
|
|
|
use samsonframework\container\definition\ClassDefinition;
|
12
|
|
|
use samsonframework\container\definition\exception\PropertyDefinitionAlreadyExistsException;
|
13
|
|
|
use samsonframework\container\definition\exception\PropertyDefinitionNotFoundException;
|
14
|
|
|
|
15
|
|
|
/**
|
16
|
|
|
* Class AnnotationPropertyAnalyzer
|
17
|
|
|
*
|
18
|
|
|
* @author Ruslan Molodyko <[email protected]>
|
19
|
|
|
*/
|
20
|
|
|
class AnnotationPropertyAnalyzer extends AbstractAnnotationAnalyzer implements PropertyAnalyzerInterface
|
21
|
|
|
{
|
22
|
|
|
/**
|
23
|
|
|
* {@inheritdoc}
|
24
|
|
|
* @throws PropertyDefinitionAlreadyExistsException
|
25
|
|
|
* @throws PropertyDefinitionNotFoundException
|
26
|
|
|
*/
|
27
|
2 |
|
public function analyze(
|
28
|
|
|
DefinitionAnalyzer $analyzer,
|
29
|
|
|
ClassDefinition $classDefinition,
|
30
|
|
|
\ReflectionProperty $reflectionProperty
|
31
|
|
|
) {
|
32
|
2 |
|
$propertyName = $reflectionProperty->getName();
|
33
|
|
|
// Resolve annotations
|
34
|
2 |
|
$annotations = $this->reader->getPropertyAnnotations($reflectionProperty);
|
35
|
2 |
|
if (count($annotations)) {
|
36
|
|
|
// Define property if not exists
|
37
|
2 |
|
if (!$classDefinition->hasProperty($propertyName)) {
|
38
|
2 |
|
$classDefinition->defineProperty($propertyName);
|
39
|
|
|
}
|
40
|
|
|
// Exec annotations
|
41
|
2 |
|
foreach ($annotations as $annotation) {
|
42
|
2 |
|
if ($annotation instanceof ResolvePropertyInterface) {
|
43
|
2 |
|
$annotation->resolveProperty($analyzer, $classDefinition, $reflectionProperty);
|
44
|
|
|
}
|
45
|
|
|
}
|
46
|
|
|
}
|
47
|
2 |
|
}
|
48
|
|
|
}
|
49
|
|
|
|