1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Automation tool mixed with code generator for easier continuous development |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hidev |
6
|
|
|
* @package hidev |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hidev\console; |
12
|
|
|
|
13
|
|
|
use hidev\base\Controller; |
14
|
|
|
use hidev\helpers\Helper; |
15
|
|
|
use Yii; |
16
|
|
|
use yii\console\Request; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Common controller behavior. |
20
|
|
|
*/ |
21
|
|
|
class CommonBehavior extends \yii\base\Behavior |
22
|
|
|
{ |
23
|
1 |
|
public function events() |
24
|
|
|
{ |
25
|
|
|
return [ |
26
|
1 |
|
Controller::EVENT_BEFORE_ACTION => 'onBeforeAction', |
27
|
|
|
Controller::EVENT_AFTER_ACTION => 'onAfterAction', |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected $beforeResult; |
32
|
|
|
|
33
|
|
|
public function onBeforeAction($event) |
34
|
|
|
{ |
35
|
|
|
$result = $this->runRequests($event->sender->before); |
36
|
|
|
if (!Helper::isResponseOk($result)) { |
37
|
|
|
$this->beforeResult = $result; |
38
|
|
|
$event->isValid = false; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getBeforeResult() |
43
|
|
|
{ |
44
|
|
|
return $this->beforeResult; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function onAfterAction($event) |
48
|
|
|
{ |
49
|
|
|
$this->runRequests($event->sender->after); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function runRequests($requests) |
53
|
|
|
{ |
54
|
|
|
foreach ($this->normalizeTasks($requests) as $request => $enabled) { |
55
|
|
|
if ($enabled) { |
56
|
|
|
$response = $this->runRequest($request); |
57
|
|
|
if (!Helper::isResponseOk($response)) { |
58
|
|
|
return $response; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
public function normalizeTasks($tasks) |
65
|
|
|
{ |
66
|
1 |
|
if (!$tasks) { |
67
|
|
|
return []; |
68
|
1 |
|
} elseif (!is_array($tasks)) { |
69
|
1 |
|
$tasks = [(string) $tasks => 1]; |
70
|
|
|
} |
71
|
1 |
|
$res = []; |
72
|
1 |
|
foreach ($tasks as $dep => $enabled) { |
73
|
1 |
|
$res[(string) (is_int($dep) ? $enabled : $dep)] = (bool) (is_int($dep) ? 1 : $enabled); |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
return $res; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Run request. |
81
|
|
|
* @param string|array $query |
82
|
|
|
* @return Response |
|
|
|
|
83
|
|
|
*/ |
84
|
|
|
public function runRequest($query) |
85
|
|
|
{ |
86
|
|
|
$request = Yii::createObject([ |
87
|
|
|
'class' => Request::class, |
88
|
|
|
'params' => is_array($query) ? $query : array_filter(explode(' ', $query)), |
89
|
|
|
]); |
90
|
|
|
|
91
|
|
|
return Yii::$app->handleRequest($request); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths