|
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\EntityMapBuilderInterface; |
|
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
|
|
|
* Билдер для генерации карты сущностей |
|
30
|
|
|
* |
|
31
|
|
|
* @var EntityMapBuilderInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $entityMapBuilder; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* EntityMapBuilderController constructor. |
|
37
|
|
|
* |
|
38
|
|
|
* @param ContainerInterface $doctrineObjectManager |
|
39
|
|
|
* @param EntityMapBuilderInterface $entityMapBuilder |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(ContainerInterface $doctrineObjectManager, EntityMapBuilderInterface $entityMapBuilder) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->setDoctrineObjectManager($doctrineObjectManager); |
|
44
|
|
|
$this->setEntityMapBuilder($entityMapBuilder); |
|
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
|
|
|
$entityMap = $this->getEntityMapBuilder()->buildEntityMapByObjectManagerName($managerName); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$result = ''; |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
return [ |
|
70
|
|
|
ConsoleModel::RESULT => $result |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Возвращает менеджер для получения ObjectManager Doctrine2 |
|
76
|
|
|
* |
|
77
|
|
|
* @return ContainerInterface |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getDoctrineObjectManager() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->doctrineObjectManager; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Устанавливает менеджер для получения ObjectManager Doctrine2 |
|
86
|
|
|
* |
|
87
|
|
|
* @param ContainerInterface $doctrineObjectManager |
|
88
|
|
|
* |
|
89
|
|
|
* @return $this |
|
90
|
|
|
*/ |
|
91
|
|
|
public function setDoctrineObjectManager(ContainerInterface $doctrineObjectManager) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->doctrineObjectManager = $doctrineObjectManager; |
|
94
|
|
|
|
|
95
|
|
|
return $this; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Возвращает билдер для генерации карты сущностей |
|
100
|
|
|
* |
|
101
|
|
|
* @return EntityMapBuilderInterface |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getEntityMapBuilder() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->entityMapBuilder; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Устанавливает билдер для генерации карты сущностей |
|
110
|
|
|
* |
|
111
|
|
|
* @param EntityMapBuilderInterface $entityMapBuilder |
|
112
|
|
|
* |
|
113
|
|
|
* @return $this |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setEntityMapBuilder(EntityMapBuilderInterface $entityMapBuilder) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->entityMapBuilder = $entityMapBuilder; |
|
118
|
|
|
|
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.