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