Skip to content

Commit 7b05d35

Browse files
committed
moved isResponseOk() to Helper class
1 parent 804c16a commit 7b05d35

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/base/Controller.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace hidev\base;
1212

1313
use hidev\console\CommonBehavior;
14+
use hidev\helpers\Helper;
1415

1516
/**
1617
* Basic controller.
@@ -61,22 +62,12 @@ public function runActions($actions)
6162
foreach ($this->normalizeTasks($actions) as $action => $enabled) {
6263
if ($enabled) {
6364
$res = $this->runAction($action);
64-
if (!static::isResponseOk($res)) {
65+
if (!Helper::isResponseOk($res)) {
6566
return $res;
6667
}
6768
}
6869
}
6970

7071
return 0;
7172
}
72-
73-
/**
74-
* Is response Ok.
75-
* @param Response|int $response
76-
* @return bool
77-
*/
78-
public static function isResponseOk($response)
79-
{
80-
return !(is_object($response) ? $response->exitStatus : $response);
81-
}
8273
}

src/console/CommonBehavior.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace hidev\console;
1212

1313
use hidev\base\Controller;
14+
use hidev\helpers\Helper;
1415
use Yii;
1516
use yii\console\Request;
1617

@@ -32,7 +33,7 @@ public function events()
3233
public function onBeforeAction($event)
3334
{
3435
$result = $this->runRequests($event->sender->before);
35-
if (!Controller::isResponseOk($result)) {
36+
if (!Helper::isResponseOk($result)) {
3637
$this->beforeResult = $result;
3738
$event->isValid = false;
3839
}
@@ -53,7 +54,7 @@ public function runRequests($requests)
5354
foreach ($this->normalizeTasks($requests) as $request => $enabled) {
5455
if ($enabled) {
5556
$response = $this->runRequest($request);
56-
if (!Controller::isResponseOk($response)) {
57+
if (!Helper::isResponseOk($response)) {
5758
return $response;
5859
}
5960
}

src/helpers/Helper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,14 @@ public static function readpassword($prompt)
108108

109109
return $password;
110110
}
111+
112+
/**
113+
* Is response Ok.
114+
* @param Response|int $response
115+
* @return bool
116+
*/
117+
public static function isResponseOk($response)
118+
{
119+
return !(is_object($response) ? $response->exitStatus : $response);
120+
}
111121
}

0 commit comments

Comments
 (0)