1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhalconExt\Http; |
4
|
|
|
|
5
|
|
|
use Phalcon\Http\Response; |
6
|
|
|
use Phalcon\Mvc\Application; |
|
|
|
|
7
|
|
|
use Phalcon\Mvc\Micro as MicroApplication; |
|
|
|
|
8
|
|
|
use Phalcon\Mvc\View; |
|
|
|
|
9
|
|
|
use PhalconExt\Di\ProvidesDi; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* A handy base for middlewares. |
13
|
|
|
* |
14
|
|
|
* @author Jitendra Adhikari <[email protected]> |
15
|
|
|
* @license MIT |
16
|
|
|
* |
17
|
|
|
* @link https://github.com/adhocore/phalcon-ext |
18
|
|
|
*/ |
19
|
|
|
abstract class BaseMiddleware |
20
|
|
|
{ |
21
|
|
|
use ProvidesDi; |
22
|
|
|
|
23
|
|
|
/** @var array */ |
24
|
|
|
protected $config = []; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
protected $configKey; |
28
|
|
|
|
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
$this->config = $this->di('config')->toArray()[$this->configKey]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Stop the app execution and disable view if possible. |
36
|
|
|
*/ |
37
|
|
|
protected function stop() |
38
|
|
|
{ |
39
|
|
|
if ($this->di('view') instanceof View) { |
40
|
|
|
$this->di('view')->disable(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ($this->isMicro()) { |
44
|
|
|
$this->di('application')->stop(); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Abort with failure response. |
50
|
|
|
* |
51
|
|
|
* @param int $status |
52
|
|
|
* @param string $body |
53
|
|
|
* |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
protected function abort(int $status, string $body = null): bool |
57
|
|
|
{ |
58
|
|
|
$this->stop(); |
59
|
|
|
|
60
|
|
|
$this->di('response')->setStatusCode($status)->setContent($body)->send(); |
61
|
|
|
|
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Checks if current app is micro. |
67
|
|
|
* |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
|
|
protected function isMicro(): bool |
71
|
|
|
{ |
72
|
|
|
return $this->di('application') instanceof MicroApplication; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get routeName and Uri tuple. |
77
|
|
|
* |
78
|
|
|
* @return array ['name', 'uri'] |
79
|
|
|
*/ |
80
|
|
|
protected function getRouteNameUri(): array |
81
|
|
|
{ |
82
|
|
|
$router = $this->di('router'); |
83
|
|
|
$route = $router->getMatchedRoute(); |
84
|
|
|
$name = $route ? $route->getName() : null; |
85
|
|
|
|
86
|
|
|
return [$name, $router->getRewriteUri()]; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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