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\PropertyInterface; |
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
|
8 |
|
public function resolve(\ReflectionClass $classData, ClassMetadata $classMetadata) |
24
|
|
|
{ |
25
|
|
|
/** @var \ReflectionProperty $property */ |
26
|
8 |
|
foreach ($classData->getProperties() as $property) { |
27
|
7 |
|
$this->resolveClassPropertyAnnotations($property, $classMetadata); |
28
|
|
|
} |
29
|
|
|
|
30
|
8 |
|
return $classMetadata; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Resolve class property annotations. |
35
|
|
|
* |
36
|
|
|
* @param \ReflectionProperty $property |
37
|
|
|
* @param ClassMetadata $classMetadata |
38
|
|
|
*/ |
39
|
7 |
|
protected function resolveClassPropertyAnnotations(\ReflectionProperty $property, ClassMetadata $classMetadata) |
40
|
|
|
{ |
41
|
|
|
// Create method metadata instance |
42
|
7 |
|
$propertyMetadata = new PropertyMetadata($classMetadata); |
43
|
7 |
|
$propertyMetadata->name = $property->getName(); |
44
|
7 |
|
$propertyMetadata->modifiers = $property->getModifiers(); |
45
|
7 |
|
$propertyMetadata->isPublic = $property->isPublic(); |
46
|
|
|
|
47
|
|
|
// Parse property type hint if present |
48
|
7 |
|
if (preg_match(self::P_PROPERTY_TYPE_HINT, $property->getDocComment(), $matches)) { |
49
|
7 |
|
list(, $propertyMetadata->typeHint) = $matches; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** @var PropertyInterface $annotation Read class annotations */ |
53
|
7 |
|
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { |
54
|
7 |
|
if ($annotation instanceof PropertyInterface) { |
55
|
7 |
|
$annotation->toPropertyMetadata($propertyMetadata); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
7 |
|
$classMetadata->propertiesMetadata[$propertyMetadata->name] = $propertyMetadata; |
60
|
7 |
|
} |
61
|
|
|
} |
62
|
|
|
|