|
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\PropertyConfiguratorInterface; |
|
9
|
|
|
use samsonframework\container\metadata\ClassMetadata; |
|
10
|
|
|
use samsonframework\container\metadata\PropertyMetadata; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class properties annotation resolver. |
|
14
|
|
|
*/ |
|
15
|
|
|
class AnnotationPropertyResolver extends AbstractAnnotationResolver implements AnnotationResolverInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** Property typeHint hint pattern */ |
|
18
|
|
|
const P_PROPERTY_TYPE_HINT = '/@var\s+(?<class>[^\s]+)/'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritDoc} |
|
22
|
|
|
*/ |
|
23
|
11 |
|
public function resolve(\ReflectionClass $classReflection, ClassMetadata $classMetadata) |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var \ReflectionProperty $property */ |
|
26
|
11 |
|
foreach ($classReflection->getProperties() as $property) { |
|
27
|
10 |
|
$this->resolveClassPropertyAnnotations($property, $classMetadata); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
11 |
|
return $classMetadata; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Resolve class property annotations. |
|
35
|
|
|
* |
|
36
|
|
|
* @param \ReflectionProperty $property |
|
37
|
|
|
* @param ClassMetadata $classMetadata |
|
38
|
|
|
*/ |
|
39
|
10 |
|
protected function resolveClassPropertyAnnotations(\ReflectionProperty $property, ClassMetadata $classMetadata) |
|
40
|
|
|
{ |
|
41
|
|
|
// Create method metadata instance |
|
42
|
10 |
|
$propertyMetadata = new PropertyMetadata($classMetadata); |
|
43
|
10 |
|
$propertyMetadata->name = $property->getName(); |
|
44
|
10 |
|
$propertyMetadata->modifiers = $property->getModifiers(); |
|
45
|
10 |
|
$propertyMetadata->isPublic = $property->isPublic(); |
|
46
|
|
|
|
|
47
|
|
|
// Parse property type hint if present |
|
48
|
10 |
|
if (preg_match(self::P_PROPERTY_TYPE_HINT, $property->getDocComment(), $matches)) { |
|
49
|
10 |
|
list(, $propertyMetadata->typeHint) = $matches; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** @var PropertyInterface $annotation Read class annotations */ |
|
53
|
10 |
|
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { |
|
54
|
10 |
|
if ($annotation instanceof PropertyConfiguratorInterface) { |
|
55
|
10 |
|
$annotation->toPropertyMetadata($propertyMetadata); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
10 |
|
$classMetadata->propertiesMetadata[$propertyMetadata->name] = $propertyMetadata; |
|
60
|
10 |
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|