Skip to content

Commit

Permalink
added handling and passing of error and result in before actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed May 8, 2018
1 parent e149f73 commit 61512d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/console/CommonBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@ public function events()
];
}

protected $beforeResult;

public function onBeforeAction($event)
{
$this->runRequests($event->sender->before);
$result = $this->runRequests($event->sender->before);
if (!Controller::isResponseOk($result)) {
$this->beforeResult = $result;
$event->isValid = false;
}
}

public function getBeforeResult()
{
return $this->beforeResult;
}

public function onAfterAction($event)
Expand Down
7 changes: 7 additions & 0 deletions src/console/CommonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ public function actions()

return $actions;
}

public function runAction($id, $params = [])
{
$result = parent::runAction($id, $params);

return isset($this->beforeResult) ? $this->beforeResult : $result;
}
}

0 comments on commit 61512d8

Please sign in to comment.