1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/nnx-framework/doctrine-fixture-module |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Nnx\DoctrineFixtureModule\Controller; |
7
|
|
|
|
8
|
|
|
use Nnx\DoctrineFixtureModule\Executor\FixtureExecutorManagerInterface; |
9
|
|
|
use Nnx\DoctrineFixtureModule\Utils\ManagerRegistryProviderInterface; |
10
|
|
|
use Zend\Mvc\Controller\AbstractConsoleController; |
11
|
|
|
use Zend\Console\Request as ConsoleRequest; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ExecutorController |
15
|
|
|
* |
16
|
|
|
* @package Nnx\DoctrineFixtureModule\Entity |
17
|
|
|
* |
18
|
|
|
*/ |
19
|
|
|
class ExecutorController extends AbstractConsoleController |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Провайдер для получения ManagerRegistry |
23
|
|
|
* |
24
|
|
|
* @var ManagerRegistryProviderInterface |
25
|
|
|
*/ |
26
|
|
|
protected $managerRegistryProvider; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Менеджер для получения Executor'ов |
30
|
|
|
* |
31
|
|
|
* @var FixtureExecutorManagerInterface |
32
|
|
|
*/ |
33
|
|
|
protected $fixtureExecutorManager; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Разрешенные методы |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $allowedMethod = [ |
41
|
|
|
'import', |
42
|
|
|
'purge' |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* ExecutorController constructor. |
47
|
|
|
* |
48
|
|
|
* @param ManagerRegistryProviderInterface $managerRegistryProvider |
49
|
|
|
* @param FixtureExecutorManagerInterface $fixtureExecutorManager |
50
|
|
|
*/ |
51
|
|
|
public function __construct(ManagerRegistryProviderInterface $managerRegistryProvider, FixtureExecutorManagerInterface $fixtureExecutorManager) |
52
|
|
|
{ |
53
|
|
|
$this->setManagerRegistryProvider($managerRegistryProvider); |
54
|
|
|
$this->setFixtureExecutorManager($fixtureExecutorManager); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* |
59
|
|
|
* |
60
|
|
|
*/ |
61
|
|
|
public function executeFixtureAction() |
62
|
|
|
{ |
63
|
|
|
$request = $this->getRequest(); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* |
69
|
|
|
* |
70
|
|
|
* @throws \Nnx\DoctrineFixtureModule\Controller\Exception\RuntimeException |
71
|
|
|
*/ |
72
|
|
|
public function runExecutorAction() |
73
|
|
|
{ |
74
|
|
|
$request = $this->getRequest(); |
75
|
|
|
if (!$request instanceof ConsoleRequest) { |
76
|
|
|
$errMsg = 'Request is not console'; |
77
|
|
|
throw new Exception\RuntimeException($errMsg); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$executorName = $request->getParam('executorName', null); |
81
|
|
|
if (null === $executorName) { |
82
|
|
|
$errMsg = 'Executor name is not defined'; |
83
|
|
|
throw new Exception\RuntimeException($errMsg); |
84
|
|
|
} |
85
|
|
|
$method = $request->getParam('method', null); |
86
|
|
|
if (null === $method) { |
87
|
|
|
$errMsg = 'Executor method not defined'; |
88
|
|
|
throw new Exception\RuntimeException($errMsg); |
89
|
|
|
} |
90
|
|
|
$normalizeMethod = strtolower($method); |
91
|
|
|
if (!in_array($normalizeMethod, $this->allowedMethod, true)) { |
92
|
|
|
$errMsg = sprintf('Invalid executor method %s', $method); |
93
|
|
|
throw new Exception\RuntimeException($errMsg); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$objectManager = $request->getParam('object-manager', null); |
|
|
|
|
97
|
|
|
|
98
|
|
|
$executor = $this->getFixtureExecutorManager()->get($executorName); |
99
|
|
|
|
100
|
|
|
switch ($method) { |
101
|
|
|
case 'import': { |
|
|
|
|
102
|
|
|
$executor->import(); |
103
|
|
|
break; |
104
|
|
|
} |
105
|
|
|
case 'purge': { |
|
|
|
|
106
|
|
|
$executor->purge(); |
107
|
|
|
break; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Возвращает провайдер для получения ManagerRegistry |
114
|
|
|
* |
115
|
|
|
* @return ManagerRegistryProviderInterface |
116
|
|
|
*/ |
117
|
|
|
public function getManagerRegistryProvider() |
118
|
|
|
{ |
119
|
|
|
return $this->managerRegistryProvider; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Устанавливает провайдер для получения ManagerRegistry |
124
|
|
|
* |
125
|
|
|
* @param ManagerRegistryProviderInterface $managerRegistryProvider |
126
|
|
|
* |
127
|
|
|
* @return $this |
128
|
|
|
*/ |
129
|
|
|
public function setManagerRegistryProvider(ManagerRegistryProviderInterface $managerRegistryProvider) |
130
|
|
|
{ |
131
|
|
|
$this->managerRegistryProvider = $managerRegistryProvider; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Возвращает менеджер для получения Executor'ов |
138
|
|
|
* |
139
|
|
|
* @return FixtureExecutorManagerInterface |
140
|
|
|
*/ |
141
|
|
|
public function getFixtureExecutorManager() |
142
|
|
|
{ |
143
|
|
|
return $this->fixtureExecutorManager; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Устанавливает менеджер для получения Executor'ов |
148
|
|
|
* |
149
|
|
|
* @param FixtureExecutorManagerInterface $fixtureExecutorManager |
150
|
|
|
* |
151
|
|
|
* @return $this |
152
|
|
|
*/ |
153
|
|
|
public function setFixtureExecutorManager($fixtureExecutorManager) |
154
|
|
|
{ |
155
|
|
|
$this->fixtureExecutorManager = $fixtureExecutorManager; |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.