1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/jms-serializer-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\JmsSerializerModule\MetadataDriver; |
7
|
|
|
|
8
|
|
|
use Interop\Container\ContainerInterface; |
9
|
|
|
use Zend\ServiceManager\FactoryInterface; |
10
|
|
|
use Zend\ServiceManager\MutableCreationOptionsInterface; |
11
|
|
|
use Zend\ServiceManager\MutableCreationOptionsTrait; |
12
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class LazyLoadingDriver |
16
|
|
|
* |
17
|
|
|
* @package Nnx\JmsSerializerModule\MetadataDriver |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
class LazyLoadingDriverFactory implements FactoryInterface, MutableCreationOptionsInterface |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
use MutableCreationOptionsTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
25
|
|
|
* |
26
|
|
|
* @return LazyLoadingDriver |
27
|
|
|
* @throws \Nnx\JmsSerializerModule\MetadataDriver\Exception\RuntimeException |
28
|
|
|
*/ |
29
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
30
|
|
|
{ |
31
|
|
|
$creationOptions = $this->getCreationOptions(); |
32
|
|
|
|
33
|
|
|
if (!array_key_exists('realDriverId', $creationOptions)) { |
34
|
|
|
$errMsg = 'RealDriverId in LazyLoadingDriver not found'; |
35
|
|
|
throw new Exception\RuntimeException($errMsg); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$realDriverId = $creationOptions['realDriverId']; |
39
|
|
|
|
40
|
|
|
if (!$serviceLocator instanceof ContainerInterface) { |
41
|
|
|
$errMsg = sprintf('Service locator not implement %s', ContainerInterface::class); |
42
|
|
|
throw new Exception\RuntimeException($errMsg); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return new LazyLoadingDriver($serviceLocator, $realDriverId); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
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.