1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/jms-serializer-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\JmsSerializerModule\NamingStrategy; |
7
|
|
|
|
8
|
|
|
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; |
9
|
|
|
use JMS\Serializer\Naming\PropertyNamingStrategyInterface; |
10
|
|
|
use Zend\ServiceManager\FactoryInterface; |
11
|
|
|
use Zend\ServiceManager\MutableCreationOptionsInterface; |
12
|
|
|
use Zend\ServiceManager\MutableCreationOptionsTrait; |
13
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class SerializedNameAnnotationStrategyFactory |
17
|
|
|
* |
18
|
|
|
* @package Nnx\JmsSerializerModule\NamingStrategy |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
class SerializedNameAnnotationStrategyFactory implements FactoryInterface, MutableCreationOptionsInterface |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
use MutableCreationOptionsTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
26
|
|
|
* |
27
|
|
|
* @return SerializedNameAnnotationStrategy |
28
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
29
|
|
|
* @throws \Nnx\JmsSerializerModule\NamingStrategy\Exception\RuntimeException |
30
|
|
|
*/ |
31
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
32
|
|
|
{ |
33
|
|
|
$creationOptions = $this->getCreationOptions(); |
34
|
|
|
|
35
|
|
|
if (!array_key_exists('delegate', $creationOptions)) { |
36
|
|
|
$errMsg = 'Delegate naming strategy not specified'; |
37
|
|
|
throw new Exception\RuntimeException($errMsg); |
38
|
|
|
} |
39
|
|
|
$delegateName = $creationOptions['delegate']; |
40
|
|
|
|
41
|
|
|
/** @var PropertyNamingStrategyInterface $delegate */ |
42
|
|
|
$delegate = $serviceLocator->get($delegateName); |
43
|
|
|
|
44
|
|
|
return new SerializedNameAnnotationStrategy($delegate); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
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.