|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://github.com/nnx-framework/doctrine |
|
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Nnx\Doctrine\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use Zend\Mvc\Controller\AbstractConsoleController; |
|
9
|
|
|
use Zend\Console\Request; |
|
10
|
|
|
use Interop\Container\ContainerInterface; |
|
11
|
|
|
use Zend\View\Model\ConsoleModel; |
|
12
|
|
|
use Nnx\Doctrine\Utils\EntityMapCacheInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class EntityMapBuilderController |
|
16
|
|
|
* |
|
17
|
|
|
* @package Nnx\Doctrine\Controller |
|
18
|
|
|
*/ |
|
19
|
|
|
class EntityMapBuilderController extends AbstractConsoleController |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Менеджер для получения ObjectManager Doctrine2 |
|
23
|
|
|
* |
|
24
|
|
|
* @var ContainerInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $doctrineObjectManager; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Сервис для кеширования EntityMap |
|
30
|
|
|
* |
|
31
|
|
|
* @var EntityMapCacheInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $entityMapCache; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* EntityMapBuilderController constructor. |
|
37
|
|
|
* |
|
38
|
|
|
* @param ContainerInterface $doctrineObjectManager |
|
39
|
|
|
* @param EntityMapCacheInterface $entityMapCache |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(ContainerInterface $doctrineObjectManager, EntityMapCacheInterface $entityMapCache) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->setDoctrineObjectManager($doctrineObjectManager); |
|
44
|
|
|
$this->setEntityMapCache($entityMapCache); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Генерация карты сущностей и сохранение ее в кеше |
|
50
|
|
|
* |
|
51
|
|
|
*/ |
|
52
|
|
|
public function buildAction() |
|
53
|
|
|
{ |
|
54
|
|
|
/** @var Request $request */ |
|
55
|
|
|
$request = $this->getRequest(); |
|
56
|
|
|
$managerName = $request->getParam('objectManager'); |
|
57
|
|
|
|
|
58
|
|
|
if (!$this->getDoctrineObjectManager()->has($managerName)) { |
|
59
|
|
|
return [ |
|
60
|
|
|
ConsoleModel::RESULT => sprintf('Doctrine ObjectManager %s not found', $managerName) |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->getEntityMapCache()->saveEntityMap($managerName); |
|
65
|
|
|
|
|
66
|
|
|
$entityMap = $this->getEntityMapCache()->loadEntityMap($managerName); |
|
67
|
|
|
|
|
68
|
|
|
if (is_array($entityMap)) { |
|
69
|
|
|
$result = "Entity map:\n"; |
|
70
|
|
|
foreach ($entityMap as $interfaceName => $className) { |
|
71
|
|
|
$result .= sprintf("Interface name: %s. Class name: %s \n", $interfaceName, $className); |
|
72
|
|
|
} |
|
73
|
|
|
} else { |
|
74
|
|
|
$result = 'Empty entity map'; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
return [ |
|
79
|
|
|
ConsoleModel::RESULT => $result |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Возвращает менеджер для получения ObjectManager Doctrine2 |
|
85
|
|
|
* |
|
86
|
|
|
* @return ContainerInterface |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getDoctrineObjectManager() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->doctrineObjectManager; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Устанавливает менеджер для получения ObjectManager Doctrine2 |
|
95
|
|
|
* |
|
96
|
|
|
* @param ContainerInterface $doctrineObjectManager |
|
97
|
|
|
* |
|
98
|
|
|
* @return $this |
|
99
|
|
|
*/ |
|
100
|
|
|
public function setDoctrineObjectManager(ContainerInterface $doctrineObjectManager) |
|
101
|
|
|
{ |
|
102
|
|
|
$this->doctrineObjectManager = $doctrineObjectManager; |
|
103
|
|
|
|
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Возвращает сервис для кеширования EntityMap |
|
109
|
|
|
* |
|
110
|
|
|
* @return EntityMapCacheInterface |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getEntityMapCache() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->entityMapCache; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Устанавливает сервис для кеширования EntityMap |
|
119
|
|
|
* |
|
120
|
|
|
* @param EntityMapCacheInterface $entityMapCache |
|
121
|
|
|
* |
|
122
|
|
|
* @return $this |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setEntityMapCache(EntityMapCacheInterface $entityMapCache) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->entityMapCache = $entityMapCache; |
|
127
|
|
|
|
|
128
|
|
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|