1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Commander project. |
4
|
|
|
* |
5
|
|
|
* @author Daniel Schröder <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace GravityMedia\Commander\Provider; |
9
|
|
|
|
10
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
11
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
12
|
|
|
use Doctrine\Common\Annotations\CachedReader; |
13
|
|
|
use Doctrine\Common\Cache\Cache; |
14
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; |
15
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; |
16
|
|
|
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
17
|
|
|
use GravityMedia\Commander\Commander; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Mapping driver provider class. |
21
|
|
|
* |
22
|
|
|
* @package GravityMedia\Commander\Provider |
23
|
|
|
*/ |
24
|
|
|
class MappingDriverProvider |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* The cache. |
28
|
|
|
* |
29
|
|
|
* @var Cache |
30
|
|
|
*/ |
31
|
|
|
protected $cache; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The mapping driver. |
35
|
|
|
* |
36
|
|
|
* @var MappingDriver |
37
|
|
|
*/ |
38
|
|
|
protected $mappingDriver; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Create mapping driver provider object. |
42
|
|
|
* |
43
|
|
|
* @param Cache $cache |
44
|
|
|
*/ |
45
|
|
|
public function __construct(Cache $cache) |
46
|
|
|
{ |
47
|
|
|
$this->cache = $cache; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get mapping driver. |
52
|
|
|
* |
53
|
|
|
* @return MappingDriver |
54
|
|
|
*/ |
55
|
|
|
public function getMappingDriver() |
56
|
|
|
{ |
57
|
|
|
if (null === $this->mappingDriver) { |
58
|
|
|
$annotationFiles = [ |
59
|
|
|
__DIR__ . '/../../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php', |
60
|
|
|
__DIR__ . '/../../vendor/gedmo/doctrine-extensions/lib/Gedmo/Mapping/Annotation/Timestampable.php', |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
foreach ($annotationFiles as $annotationFile) { |
64
|
|
|
AnnotationRegistry::registerFile($annotationFile); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** @var AnnotationReader $reader */ |
68
|
|
|
$reader = new CachedReader(new AnnotationReader(), $this->cache); |
69
|
|
|
|
70
|
|
|
$annotationDriver = new AnnotationDriver($reader, [__DIR__ . '/../ORM']); |
71
|
|
|
|
72
|
|
|
$driverChain = new MappingDriverChain(); |
73
|
|
|
$driverChain->addDriver($annotationDriver, Commander::ENTITY_NAMESPACE); |
74
|
|
|
|
75
|
|
|
$this->mappingDriver = $driverChain; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this->mappingDriver; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|