|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/nnx-framework/doctrine |
|
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Nnx\Doctrine\Hydrator; |
|
7
|
|
|
|
|
8
|
|
|
use Zend\ServiceManager\AbstractFactoryInterface; |
|
9
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
|
10
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
11
|
|
|
use DoctrineModule\Stdlib\Hydrator\DoctrineObject; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class DoctrineObjectHydratorAbstractFactory |
|
16
|
|
|
* |
|
17
|
|
|
* @package Nnx\Doctrine\Hydrator |
|
18
|
|
|
*/ |
|
19
|
|
|
class DoctrineObjectHydratorAbstractFactory implements AbstractFactoryInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Флаг определяет была ли инициализированна фабрика |
|
23
|
|
|
* |
|
24
|
|
|
* @var bool |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $isInit = false; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Контейнер для создания DoctrineObjectHydrator |
|
30
|
|
|
* |
|
31
|
|
|
* @var DoctrineObjectHydratorLocatorInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $doctrineObjectHydratorLocator; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Инициализация фабрики |
|
37
|
|
|
* |
|
38
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
39
|
|
|
* |
|
40
|
|
|
* @return boolean; |
|
|
|
|
|
|
41
|
|
|
* |
|
42
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function init(ServiceLocatorInterface $serviceLocator) |
|
45
|
|
|
{ |
|
46
|
|
|
if (true === $this->isInit) { |
|
47
|
|
|
return $this->isInit; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$appServiceLocator = $serviceLocator; |
|
51
|
|
|
if ($serviceLocator instanceof AbstractPluginManager) { |
|
52
|
|
|
$appServiceLocator = $serviceLocator->getServiceLocator(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** @var DoctrineObjectHydratorLocatorInterface $doctrineObjectHydratorLocator */ |
|
56
|
|
|
$doctrineObjectHydratorLocator = $appServiceLocator->get(DoctrineObjectHydratorLocatorInterface::class); |
|
57
|
|
|
$this->setDoctrineObjectHydratorLocator($doctrineObjectHydratorLocator); |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$this->isInit = true; |
|
61
|
|
|
return $this->isInit; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @inheritdoc |
|
66
|
|
|
* |
|
67
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
68
|
|
|
* @param $name |
|
69
|
|
|
* @param $requestedName |
|
70
|
|
|
* |
|
71
|
|
|
* @return bool |
|
72
|
|
|
* |
|
73
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
|
74
|
|
|
*/ |
|
75
|
|
|
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->init($serviceLocator); |
|
78
|
|
|
return $this->getDoctrineObjectHydratorLocator()->has($requestedName); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @inheritdoc |
|
83
|
|
|
* |
|
84
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
85
|
|
|
* @param $name |
|
86
|
|
|
* @param $requestedName |
|
87
|
|
|
* |
|
88
|
|
|
* @return DoctrineObject |
|
89
|
|
|
* |
|
90
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
|
91
|
|
|
* @throws \Interop\Container\Exception\NotFoundException |
|
92
|
|
|
* @throws \Interop\Container\Exception\ContainerException |
|
93
|
|
|
*/ |
|
94
|
|
|
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
|
95
|
|
|
{ |
|
96
|
|
|
$this->init($serviceLocator); |
|
97
|
|
|
return $this->getDoctrineObjectHydratorLocator()->get($requestedName); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Возвращает контейнер для создания DoctrineObjectHydrator |
|
102
|
|
|
* |
|
103
|
|
|
* @return DoctrineObjectHydratorLocatorInterface |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getDoctrineObjectHydratorLocator() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->doctrineObjectHydratorLocator; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Устанавливает контейнер для создания DoctrineObjectHydrator |
|
112
|
|
|
* |
|
113
|
|
|
* @param DoctrineObjectHydratorLocatorInterface $doctrineObjectHydratorLocator |
|
114
|
|
|
* |
|
115
|
|
|
* @return $this |
|
116
|
|
|
*/ |
|
117
|
|
|
public function setDoctrineObjectHydratorLocator(DoctrineObjectHydratorLocatorInterface $doctrineObjectHydratorLocator) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->doctrineObjectHydratorLocator = $doctrineObjectHydratorLocator; |
|
120
|
|
|
|
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.