Completed
Push — master ( 272693...b768a3 )
by Daniel
04:04
created

MappingDriverProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 3
c 3
b 1
f 0
lcom 1
cbo 4
dl 0
loc 48
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMappingDriver() 0 16 2
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\CachedReader;
12
use Doctrine\Common\Cache\Cache;
13
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
14
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
15
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
16
use GravityMedia\Commander\Commander;
17
18
/**
19
 * Mapping driver provider class.
20
 *
21
 * @package GravityMedia\Commander\Provider
22
 */
23
class MappingDriverProvider
24
{
25
    /**
26
     * The cache.
27
     *
28
     * @var Cache
29
     */
30
    protected $cache;
31
32
    /**
33
     * The mapping driver.
34
     *
35
     * @var MappingDriver
36
     */
37
    protected $mappingDriver;
38
39
    /**
40
     * Create mapping driver provider object.
41
     *
42
     * @param Cache $cache
43
     */
44
    public function __construct(Cache $cache)
45
    {
46
        $this->cache = $cache;
47
    }
48
49
    /**
50
     * Get mapping driver.
51
     *
52
     * @return MappingDriver
53
     */
54
    public function getMappingDriver()
55
    {
56
        if (null === $this->mappingDriver) {
57
            /** @var AnnotationReader $reader */
58
            $reader = new CachedReader(new AnnotationReader(), $this->cache);
59
60
            $annotationDriver = new AnnotationDriver($reader, [__DIR__ . '/../ORM']);
61
62
            $driverChain = new MappingDriverChain();
63
            $driverChain->addDriver($annotationDriver, Commander::ENTITY_NAMESPACE);
64
65
            $this->mappingDriver = $driverChain;
66
        }
67
68
        return $this->mappingDriver;
69
    }
70
}
71