|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhalconExt\Cli; |
|
4
|
|
|
|
|
5
|
|
|
use Phalcon\Cli\Console; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
trait MiddlewareTrait |
|
8
|
|
|
{ |
|
9
|
|
|
protected $middlewares = [ |
|
10
|
|
|
Middleware\Factory::class, |
|
11
|
|
|
]; |
|
12
|
|
|
|
|
13
|
|
|
protected function bindEvents(Console $console) |
|
14
|
|
|
{ |
|
15
|
|
|
$evm = $this->di('eventsManager'); |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
$evm->attach('dispatch', $console); |
|
18
|
|
|
$console->setEventsManager($evm); |
|
19
|
|
|
|
|
20
|
|
|
$this->di('dispatcher')->setEventsManager($evm); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function middleware(string $class): self |
|
24
|
|
|
{ |
|
25
|
|
|
$this->middlewares[] = $class; |
|
26
|
|
|
|
|
27
|
|
|
return $this; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Bulk setter/getter. |
|
32
|
|
|
* |
|
33
|
|
|
* @param array $middlewares Class names. |
|
34
|
|
|
* |
|
35
|
|
|
* @return array|self |
|
36
|
|
|
*/ |
|
37
|
|
|
public function middlewares(array $middlewares = []) |
|
38
|
|
|
{ |
|
39
|
|
|
if (\func_num_args() > 0) { |
|
40
|
|
|
$this->middlewares = \array_unique(\array_merge($this->middlewares, $middlewares)); |
|
41
|
|
|
|
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $this->middlewares; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function beforeExecuteRoute(): bool |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->relay('before'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function afterExecuteRoute(): bool |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->relay('after'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function relay(string $event): bool |
|
59
|
|
|
{ |
|
60
|
|
|
foreach ($this->middlewares as $middleware) { |
|
61
|
|
|
if (!$this->call($event, $middleware)) { |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return true; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function call(string $event, $middleware): bool |
|
70
|
|
|
{ |
|
71
|
|
|
if (\is_string($middleware)) { |
|
72
|
|
|
$middleware = $this->di($middleware); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if (!\method_exists($middleware, $event)) { |
|
76
|
|
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return $middleware->$event($this->di('console')); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
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