|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2018 Gerrit Addiks. |
|
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
|
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
|
7
|
|
|
* @license GPL-3.0 |
|
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Addiks\RDMBundle\Mapping\DriverFactories; |
|
12
|
|
|
|
|
13
|
|
|
use Addiks\RDMBundle\Mapping\DriverFactories\MappingDriverFactoryInterface; |
|
14
|
|
|
use Doctrine\Persistence\Mapping\Driver\MappingDriver; |
|
15
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface; |
|
16
|
|
|
use Psr\Cache\CacheItemPoolInterface; |
|
17
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\CachedMappingDriver; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
19
|
|
|
|
|
20
|
|
|
final class CachedMappingDriverFactory implements MappingDriverFactoryInterface |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var MappingDriverFactoryInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $innerMappingDriverFactory; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var CacheItemPoolInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $cacheItemPool; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var ContainerInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $container; |
|
37
|
|
|
|
|
38
|
7 |
|
public function __construct( |
|
39
|
|
|
ContainerInterface $container, |
|
40
|
|
|
MappingDriverFactoryInterface $innerMappingDriverFactory, |
|
41
|
|
|
CacheItemPoolInterface $cacheItemPool |
|
42
|
|
|
) { |
|
43
|
7 |
|
$this->container = $container; |
|
44
|
7 |
|
$this->innerMappingDriverFactory = $innerMappingDriverFactory; |
|
45
|
7 |
|
$this->cacheItemPool = $cacheItemPool; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
7 |
|
public function createRDMMappingDriver( |
|
49
|
|
|
MappingDriver $mappingDriver |
|
50
|
|
|
): ?MappingDriverInterface { |
|
51
|
|
|
/** @var ?MappingDriverInterface $rdmMappingDriver */ |
|
52
|
7 |
|
$rdmMappingDriver = null; |
|
53
|
|
|
|
|
54
|
|
|
/** @var MappingDriverInterface $innerRdmMappingDriver */ |
|
55
|
7 |
|
$innerRdmMappingDriver = $this->innerMappingDriverFactory->createRDMMappingDriver($mappingDriver); |
|
56
|
|
|
|
|
57
|
7 |
|
if ($innerRdmMappingDriver instanceof MappingDriverInterface) { |
|
|
|
|
|
|
58
|
7 |
|
$rdmMappingDriver = new CachedMappingDriver( |
|
59
|
|
|
$innerRdmMappingDriver, |
|
60
|
7 |
|
$this->container, |
|
61
|
7 |
|
$this->cacheItemPool |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
7 |
|
return $rdmMappingDriver; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|