1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/doctrine |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\Doctrine\Utils; |
7
|
|
|
|
8
|
|
|
use Doctrine\Common\Cache\VoidCache; |
9
|
|
|
use Zend\ServiceManager\FactoryInterface; |
10
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
11
|
|
|
use Nnx\ModuleOptions\ModuleOptionsPluginManagerInterface; |
12
|
|
|
use Nnx\Doctrine\Options\ModuleOptionsInterface; |
13
|
|
|
use Doctrine\Common\Cache\Cache; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class EntityMapCacheFactory |
17
|
|
|
* |
18
|
|
|
* @package Nnx\Doctrine\Utils |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
class EntityMapCacheFactory implements FactoryInterface |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
24
|
|
|
* |
25
|
|
|
* @return EntityMapBuilder |
26
|
|
|
* |
27
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
28
|
|
|
*/ |
29
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
30
|
|
|
{ |
31
|
|
|
/** @var EntityMapBuilderInterface $entityMapBuilder */ |
32
|
|
|
$entityMapBuilder = $serviceLocator->get(EntityMapBuilderInterface::class); |
33
|
|
|
|
34
|
|
|
/** @var ModuleOptionsPluginManagerInterface $moduleOptionsManager */ |
35
|
|
|
$moduleOptionsManager = $serviceLocator->get(ModuleOptionsPluginManagerInterface::class); |
36
|
|
|
/** @var ModuleOptionsInterface $moduleOptions */ |
37
|
|
|
$moduleOptions = $moduleOptionsManager->get(ModuleOptionsInterface::class); |
38
|
|
|
$cacheServiceName = $moduleOptions->getEntityMapDoctrineCache(); |
39
|
|
|
|
40
|
|
|
if (null === $cacheServiceName) { |
41
|
|
|
$cache = new VoidCache(); |
42
|
|
|
} else { |
43
|
|
|
/** @var Cache $cache */ |
44
|
|
|
$cache = $serviceLocator->get($cacheServiceName); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
return new EntityMapCache($entityMapBuilder, $cache, $moduleOptions); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.