Skip to content

Commit f1c2925

Browse files
committed
up: add before run action methods
1 parent c24919a commit f1c2925

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Controller.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ protected function createDefinition(): InputDefinition
265265
return $this->definition;
266266
}
267267

268+
/**
269+
* Before controller method execute
270+
*
271+
* @return boolean It MUST return TRUE to continue execute. if return False, will stop run.
272+
*/
273+
protected function beforeAction(): bool
274+
{
275+
return true;
276+
}
277+
278+
/**
279+
* After controller method execute
280+
*/
281+
protected function afterAction(): void
282+
{
283+
}
284+
268285
/**
269286
* Run command action in the group
270287
*
@@ -291,6 +308,11 @@ final public function execute($input, $output)
291308
// if (method_exists($this, $method) && (($rfm = new ReflectionMethod($this, $method)) && $rfm->isPublic())) {
292309
if (method_exists($this, $method)) {
293310
// before run action
311+
if (!$this->beforeAction()) {
312+
$this->debugf('beforeAction() returns FALSE, interrupt processing continues');
313+
return 0;
314+
}
315+
294316
if (method_exists($this, $beforeFunc = 'before' . ucfirst($action))) {
295317
$beforeOk = $this->$beforeFunc($input, $output);
296318
if ($beforeOk === false) {
@@ -307,6 +329,7 @@ final public function execute($input, $output)
307329
$this->$after($input, $output);
308330
}
309331

332+
$this->afterAction();
310333
return $result;
311334
}
312335

0 commit comments

Comments
 (0)