1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/old-town/workflow-zf2-dispatch |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace OldTown\Workflow\ZF2\Dispatch\Dispatcher; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class RunWorkflowParam |
10
|
|
|
* |
11
|
|
|
* @package OldTown\Workflow\ZF2\Dispatch\Dispatcher |
12
|
|
|
*/ |
13
|
|
|
class RunWorkflowParam implements RunWorkflowParamInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Тип запуска workflow (doAction или initialize) |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $runType; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Имя менеджера workflow |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $managerName; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Имя запускаемого действия |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $actionName; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Имя workflow |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $workflowName; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* id запускаемого процесса |
45
|
|
|
* |
46
|
|
|
* @var integer |
47
|
|
|
*/ |
48
|
|
|
protected $entryId; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Разрешенные типы запуска workflow |
52
|
|
|
* |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $allowWorkflowRunType = [ |
56
|
|
|
self::WORKFLOW_RUN_TYPE_DO_ACTION => self::WORKFLOW_RUN_TYPE_DO_ACTION, |
57
|
|
|
self::WORKFLOW_RUN_INITIALIZE => self::WORKFLOW_RUN_INITIALIZE, |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Возвращает тип запуска workflow (doAction или initialize) |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function getRunType() |
66
|
|
|
{ |
67
|
|
|
return $this->runType; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Устанавливает тип запуска workflow (doAction или initialize) |
72
|
|
|
* |
73
|
|
|
* @param string $runType |
74
|
|
|
* |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function setRunType($runType) |
78
|
|
|
{ |
79
|
|
|
$this->runType = $runType; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Имя запускаемого действия |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getActionName() |
90
|
|
|
{ |
91
|
|
|
return $this->actionName; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Устанавливает имя запускаемого действия |
96
|
|
|
* |
97
|
|
|
* @param string $actionName |
98
|
|
|
* |
99
|
|
|
* @return $this |
100
|
|
|
*/ |
101
|
|
|
public function setActionName($actionName) |
102
|
|
|
{ |
103
|
|
|
$this->actionName = $actionName; |
104
|
|
|
|
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Имя workflow |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function getWorkflowName() |
114
|
|
|
{ |
115
|
|
|
return $this->workflowName; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Устанавливает имя workflow |
120
|
|
|
* |
121
|
|
|
* @param string $workflowName |
122
|
|
|
* |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
|
|
public function setWorkflowName($workflowName) |
126
|
|
|
{ |
127
|
|
|
$this->workflowName = $workflowName; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* id запускаемого процесса |
134
|
|
|
* |
135
|
|
|
* @return int |
136
|
|
|
*/ |
137
|
|
|
public function getEntryId() |
138
|
|
|
{ |
139
|
|
|
return $this->entryId; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Устанавливает id запускаемого процесса |
144
|
|
|
* |
145
|
|
|
* @param int $entryId |
146
|
|
|
* |
147
|
|
|
* @return $this |
148
|
|
|
*/ |
149
|
|
|
public function setEntryId($entryId) |
150
|
|
|
{ |
151
|
|
|
$this->entryId = $entryId; |
152
|
|
|
|
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Возвращает имя менеджера workflow |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
|
|
public function getManagerName() |
162
|
|
|
{ |
163
|
|
|
return $this->managerName; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Устанавливает имя менеджера workflow |
168
|
|
|
* |
169
|
|
|
* @param string $managerName |
170
|
|
|
* |
171
|
|
|
* @return $this |
172
|
|
|
*/ |
173
|
|
|
public function setManagerName($managerName) |
174
|
|
|
{ |
175
|
|
|
$this->managerName = $managerName; |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Проверка валидности параметров |
182
|
|
|
* |
183
|
|
|
* @throws Exception\InvalidArgumentException |
184
|
|
|
*/ |
185
|
|
|
public function valid() |
186
|
|
|
{ |
187
|
|
|
if (null === $this->getManagerName()) { |
188
|
|
|
$errMsg = 'No workflow manager'; |
189
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if (null === $this->getActionName()) { |
193
|
|
|
$errMsg = 'Not Specified action for workflow'; |
194
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$workflowActivity = $this->getRunType(); |
198
|
|
|
if (!array_key_exists($workflowActivity, $this->allowWorkflowRunType)) { |
199
|
|
|
$errMsg = sprintf('Invalid activity %s', $workflowActivity); |
200
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
View Code Duplication |
if (static::WORKFLOW_RUN_INITIALIZE === $workflowActivity && null === $this->getWorkflowName()) { |
|
|
|
|
204
|
|
|
$errMsg = 'Not specified name workflow'; |
205
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
View Code Duplication |
if (static::WORKFLOW_RUN_TYPE_DO_ACTION === $workflowActivity && null === $this->getEntryId()) { |
|
|
|
|
209
|
|
|
$errMsg = 'Not specified entryId'; |
210
|
|
|
throw new Exception\InvalidArgumentException($errMsg); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.