|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Novaway\Component\OpenGraph\Metadata\Driver; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\Reader; |
|
6
|
|
|
use Metadata\Driver\DriverInterface; |
|
7
|
|
|
use Novaway\Component\OpenGraph\Annotation\GraphNode; |
|
8
|
|
|
use Novaway\Component\OpenGraph\Annotation\NamespaceNode; |
|
9
|
|
|
use Novaway\Component\OpenGraph\Metadata\ClassMetadata; |
|
10
|
|
|
use Novaway\Component\OpenGraph\Metadata\MetadataValue; |
|
11
|
|
|
use Novaway\Component\OpenGraph\Metadata\MethodMetadata; |
|
12
|
|
|
use Novaway\Component\OpenGraph\Metadata\PropertyMetadata; |
|
13
|
|
|
|
|
14
|
|
|
class AnnotationDriver implements DriverInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var Reader */ |
|
17
|
|
|
private $reader; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Constructor |
|
22
|
|
|
* |
|
23
|
|
|
* @param Reader $reader |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct(Reader $reader) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->reader = $reader; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Load metadata class |
|
32
|
|
|
* |
|
33
|
|
|
* @param \ReflectionClass $class |
|
34
|
|
|
* @return ClassMetadata |
|
35
|
|
|
*/ |
|
36
|
|
|
public function loadMetadataForClass(\ReflectionClass $class) |
|
37
|
|
|
{ |
|
38
|
|
|
$classMetadata = new ClassMetadata($class->name); |
|
39
|
|
|
$classMetadata->fileResources[] = $class->getFileName(); |
|
40
|
|
|
|
|
41
|
|
|
foreach ($this->reader->getClassAnnotations($class) as $annotation) { |
|
42
|
|
|
if ($annotation instanceof NamespaceNode) { |
|
43
|
|
|
$classMetadata->addGraphNamespace($annotation); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if ($annotation instanceof GraphNode) { |
|
47
|
|
|
$classMetadata->addGraphMetadata($annotation, new MetadataValue($annotation->value)); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
foreach ($class->getProperties() as $property) { |
|
52
|
|
|
foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { |
|
53
|
|
|
if ($annotation instanceof GraphNode) { |
|
54
|
|
|
$classMetadata->addGraphMetadata($annotation, new PropertyMetadata($class->name, $property->name)); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
foreach ($class->getMethods() as $method) { |
|
60
|
|
|
foreach ($this->reader->getMethodAnnotations($method) as $annotation) { |
|
61
|
|
|
if ($annotation instanceof GraphNode) { |
|
62
|
|
|
$classMetadata->addGraphMetadata($annotation, new MethodMetadata($class->name, $method->name)); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $classMetadata; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|