|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/nnx-framework/jms-serializer-module |
|
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Nnx\JmsSerializerModule\ObjectConstructor\DoctrineObjectConstructor; |
|
7
|
|
|
|
|
8
|
|
|
use Nnx\JmsSerializerModule\DataContainer\DataContainerInterface; |
|
9
|
|
|
use Nnx\JmsSerializerModule\DataContainer\EntityInterface; |
|
10
|
|
|
use Zend\ServiceManager\FactoryInterface; |
|
11
|
|
|
use Zend\ServiceManager\MutableCreationOptionsInterface; |
|
12
|
|
|
use Zend\ServiceManager\MutableCreationOptionsTrait; |
|
13
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class DataFactory |
|
17
|
|
|
* |
|
18
|
|
|
* @package Nnx\JmsSerializerModule\ObjectConstructor\DoctrineObjectConstructor |
|
19
|
|
|
*/ |
|
20
|
|
|
class DataFactory implements FactoryInterface, MutableCreationOptionsInterface |
|
21
|
|
|
{ |
|
22
|
|
|
use MutableCreationOptionsTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
26
|
|
|
* |
|
27
|
|
|
* @return Data |
|
28
|
|
|
* @throws \Nnx\JmsSerializerModule\ObjectConstructor\DoctrineObjectConstructor\Exception\RuntimeException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
|
31
|
|
|
{ |
|
32
|
|
|
$creationOptions = $this->getCreationOptions(); |
|
33
|
|
|
if (!array_key_exists('dataContainer', $creationOptions)) { |
|
34
|
|
|
$errMsg = 'Data container not found in creation options'; |
|
35
|
|
|
throw new Exception\RuntimeException($errMsg); |
|
36
|
|
|
} |
|
37
|
|
|
/** @var DataContainerInterface $dataContainer */ |
|
38
|
|
|
$dataContainer = $creationOptions['dataContainer']; |
|
39
|
|
|
|
|
40
|
|
|
if (!array_key_exists('entity', $creationOptions)) { |
|
41
|
|
|
$errMsg = 'Entity not found in creation options'; |
|
42
|
|
|
throw new Exception\RuntimeException($errMsg); |
|
43
|
|
|
} |
|
44
|
|
|
/** @var EntityInterface $entity */ |
|
45
|
|
|
$entity = $creationOptions['entity']; |
|
46
|
|
|
|
|
47
|
|
|
return new Data($dataContainer, $entity); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|