|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/old-town/workflow-zf2-dispatch |
|
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace OldTown\Workflow\ZF2\Dispatch\Metadata\Reader; |
|
7
|
|
|
|
|
8
|
|
|
use OldTown\Workflow\ZF2\Dispatch\Metadata\MetadataInterface; |
|
9
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
|
10
|
|
|
use Doctrine\Common\Annotations\Reader as DoctrineAnnotationsReaderInterface; |
|
11
|
|
|
use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader; |
|
12
|
|
|
use OldTown\Workflow\ZF2\Dispatch\Metadata\ReaderInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class AbstractReader |
|
16
|
|
|
* |
|
17
|
|
|
* @package OldTown\Workflow\ZF2\Dispatch\Metadata\Reader |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class AbstractAnnotationReader implements ReaderInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var DoctrineAnnotationsReaderInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $reader; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Кеш загруженных метаданных |
|
28
|
|
|
* |
|
29
|
|
|
* @var MetadataInterface[] |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $classAnnotations = []; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* |
|
35
|
|
|
* @throws Exception\AnnotationReaderException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->init(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Иницилазия |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
* @throws Exception\AnnotationReaderException |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function init() |
|
49
|
|
|
{ |
|
50
|
|
|
try { |
|
51
|
|
|
AnnotationRegistry::registerLoader(function ($class) { |
|
52
|
|
|
return (bool) class_exists($class); |
|
53
|
|
|
}); |
|
54
|
|
|
} catch (\Exception $e) { |
|
55
|
|
|
throw new Exception\AnnotationReaderException($e->getMessage(), $e->getCode(), $e); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return DoctrineAnnotationsReaderInterface |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getReader() |
|
63
|
|
|
{ |
|
64
|
|
|
if ($this->reader) { |
|
65
|
|
|
return $this->reader; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$this->reader = new DoctrineAnnotationReader(); |
|
69
|
|
|
|
|
70
|
|
|
return $this->reader; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param DoctrineAnnotationsReaderInterface $reader |
|
75
|
|
|
* |
|
76
|
|
|
* @return $this |
|
77
|
|
|
*/ |
|
78
|
|
|
public function setReader(DoctrineAnnotationsReaderInterface $reader) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->reader = $reader; |
|
81
|
|
|
|
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|