From 74a9bde25dc23ab01d1daa0a54187666fc78a61b Mon Sep 17 00:00:00 2001 From: rhertogh Date: Mon, 26 Jun 2023 19:52:21 +0200 Subject: [PATCH 1/2] Allow post-processing of action result --- framework/base/Action.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/base/Action.php b/framework/base/Action.php index 45d95c59cbf..ba33bc47864 100644 --- a/framework/base/Action.php +++ b/framework/base/Action.php @@ -91,7 +91,7 @@ public function runWithParams($params) } if ($this->beforeRun()) { $result = call_user_func_array([$this, 'run'], $args); - $this->afterRun(); + $result = $this->afterRun($result); return $result; } @@ -115,7 +115,8 @@ protected function beforeRun() * This method is called right after `run()` is executed. * You may override this method to do post-processing work for the action run. */ - protected function afterRun() + protected function afterRun($result) { + return $result; } } From 5c78f02266aef065b22ab5818389a4bf450f2265 Mon Sep 17 00:00:00 2001 From: rhertogh Date: Thu, 29 Jun 2023 20:30:28 +0200 Subject: [PATCH 2/2] Added $args parameter to `\yii\base\Action::beforeRun()` and updated phpdocs --- framework/base/Action.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/framework/base/Action.php b/framework/base/Action.php index ba33bc47864..0f4e6dc78b9 100644 --- a/framework/base/Action.php +++ b/framework/base/Action.php @@ -89,7 +89,7 @@ public function runWithParams($params) if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } - if ($this->beforeRun()) { + if ($this->beforeRun($args)) { $result = call_user_func_array([$this, 'run'], $args); $result = $this->afterRun($result); @@ -104,9 +104,10 @@ public function runWithParams($params) * You may override this method to do preparation work for the action run. * If the method returns false, it will cancel the action. * + * @param array $args * @return bool whether to run the action. */ - protected function beforeRun() + protected function beforeRun($args) { return true; } @@ -114,6 +115,8 @@ protected function beforeRun() /** * This method is called right after `run()` is executed. * You may override this method to do post-processing work for the action run. + * + * @param mixed $result */ protected function afterRun($result) {