1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Valkyrja Framework package. |
7
|
|
|
* |
8
|
|
|
* (c) Melech Mizrachi <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Valkyrja\Cli\Middleware\Provider; |
15
|
|
|
|
16
|
|
|
use Valkyrja\Application\Env; |
|
|
|
|
17
|
|
|
use Valkyrja\Cli\Middleware\Contract\CommandDispatchedMiddleware; |
18
|
|
|
use Valkyrja\Cli\Middleware\Contract\CommandMatchedMiddleware; |
19
|
|
|
use Valkyrja\Cli\Middleware\Contract\CommandNotMatchedMiddleware; |
20
|
|
|
use Valkyrja\Cli\Middleware\Contract\ExitedMiddleware; |
21
|
|
|
use Valkyrja\Cli\Middleware\Contract\InputReceivedMiddleware; |
22
|
|
|
use Valkyrja\Cli\Middleware\Contract\ThrowableCaughtMiddleware; |
23
|
|
|
use Valkyrja\Cli\Middleware\Handler; |
24
|
|
|
use Valkyrja\Cli\Middleware\Handler\Contract\CommandDispatchedHandler; |
25
|
|
|
use Valkyrja\Cli\Middleware\Handler\Contract\CommandMatchedHandler; |
26
|
|
|
use Valkyrja\Cli\Middleware\Handler\Contract\CommandNotMatchedHandler; |
27
|
|
|
use Valkyrja\Cli\Middleware\Handler\Contract\ExitedHandler; |
28
|
|
|
use Valkyrja\Cli\Middleware\Handler\Contract\InputReceivedHandler; |
29
|
|
|
use Valkyrja\Cli\Middleware\Handler\Contract\ThrowableCaughtHandler; |
30
|
|
|
use Valkyrja\Container\Contract\Container; |
31
|
|
|
use Valkyrja\Container\Support\Provider; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class ServiceProvider. |
35
|
|
|
* |
36
|
|
|
* @author Melech Mizrachi |
37
|
|
|
*/ |
38
|
|
|
final class ServiceProvider extends Provider |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @inheritDoc |
42
|
|
|
*/ |
43
|
|
|
public static function publishers(): array |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
InputReceivedHandler::class => [self::class, 'publishInputReceivedHandler'], |
47
|
|
|
ThrowableCaughtHandler::class => [self::class, 'publishThrowableCaughtHandler'], |
48
|
|
|
CommandMatchedHandler::class => [self::class, 'publishCommandMatchedHandler'], |
49
|
|
|
CommandNotMatchedHandler::class => [self::class, 'publishCommandNotMatchedHandler'], |
50
|
|
|
CommandDispatchedHandler::class => [self::class, 'publishCommandDispatchedHandler'], |
51
|
|
|
ExitedHandler::class => [self::class, 'publishExitedHandler'], |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritDoc |
57
|
|
|
*/ |
58
|
|
|
public static function provides(): array |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
InputReceivedHandler::class, |
62
|
|
|
CommandDispatchedHandler::class, |
63
|
|
|
ThrowableCaughtHandler::class, |
64
|
|
|
CommandMatchedHandler::class, |
65
|
|
|
CommandNotMatchedHandler::class, |
66
|
|
|
ExitedHandler::class, |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Publish the RequestReceivedHandler service. |
72
|
|
|
* |
73
|
|
|
* @param Container $container The container |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public static function publishInputReceivedHandler(Container $container): void |
78
|
|
|
{ |
79
|
|
|
$env = $container->getSingleton(Env::class); |
80
|
|
|
/** @var class-string<InputReceivedMiddleware>[] $middleware */ |
81
|
|
|
$middleware = $env::CLI_MIDDLEWARE_INPUT_RECEIVED; |
82
|
|
|
|
83
|
|
|
$container->setSingleton( |
84
|
|
|
InputReceivedHandler::class, |
85
|
|
|
$handler = new Handler\InputReceivedHandler($container) |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$handler->add(...$middleware); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Publish the RouteDispatchedHandler service. |
93
|
|
|
* |
94
|
|
|
* @param Container $container The container |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public static function publishCommandDispatchedHandler(Container $container): void |
99
|
|
|
{ |
100
|
|
|
$env = $container->getSingleton(Env::class); |
101
|
|
|
/** @var class-string<CommandDispatchedMiddleware>[] $middleware */ |
102
|
|
|
$middleware = $env::CLI_MIDDLEWARE_COMMAND_DISPATCHED; |
103
|
|
|
|
104
|
|
|
$container->setSingleton( |
105
|
|
|
CommandDispatchedHandler::class, |
106
|
|
|
$handler = new Handler\CommandDispatchedHandler($container) |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$handler->add(...$middleware); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Publish the ThrowableCaughtHandler service. |
114
|
|
|
* |
115
|
|
|
* @param Container $container The container |
116
|
|
|
* |
117
|
|
|
* @return void |
118
|
|
|
*/ |
119
|
|
|
public static function publishThrowableCaughtHandler(Container $container): void |
120
|
|
|
{ |
121
|
|
|
$env = $container->getSingleton(Env::class); |
122
|
|
|
/** @var class-string<ThrowableCaughtMiddleware>[] $middleware */ |
123
|
|
|
$middleware = $env::CLI_MIDDLEWARE_THROWABLE_CAUGHT; |
124
|
|
|
|
125
|
|
|
$container->setSingleton( |
126
|
|
|
ThrowableCaughtHandler::class, |
127
|
|
|
$handler = new Handler\ThrowableCaughtHandler($container) |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$handler->add(...$middleware); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Publish the RouteMatchedHandler service. |
135
|
|
|
* |
136
|
|
|
* @param Container $container The container |
137
|
|
|
* |
138
|
|
|
* @return void |
139
|
|
|
*/ |
140
|
|
|
public static function publishCommandMatchedHandler(Container $container): void |
141
|
|
|
{ |
142
|
|
|
$env = $container->getSingleton(Env::class); |
143
|
|
|
/** @var class-string<CommandMatchedMiddleware>[] $middleware */ |
144
|
|
|
$middleware = $env::CLI_MIDDLEWARE_COMMAND_MATCHED; |
145
|
|
|
|
146
|
|
|
$container->setSingleton( |
147
|
|
|
CommandMatchedHandler::class, |
148
|
|
|
$handler = new Handler\CommandMatchedHandler($container) |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
$handler->add(...$middleware); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Publish the RouteNotMatchedHandler service. |
156
|
|
|
* |
157
|
|
|
* @param Container $container The container |
158
|
|
|
* |
159
|
|
|
* @return void |
160
|
|
|
*/ |
161
|
|
|
public static function publishCommandNotMatchedHandler(Container $container): void |
162
|
|
|
{ |
163
|
|
|
$env = $container->getSingleton(Env::class); |
164
|
|
|
/** @var class-string<CommandNotMatchedMiddleware>[] $middleware */ |
165
|
|
|
$middleware = $env::CLI_MIDDLEWARE_COMMAND_NOT_MATCHED; |
166
|
|
|
|
167
|
|
|
$container->setSingleton( |
168
|
|
|
CommandNotMatchedHandler::class, |
169
|
|
|
$handler = new Handler\CommandNotMatchedHandler($container) |
170
|
|
|
); |
171
|
|
|
|
172
|
|
|
$handler->add(...$middleware); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Publish the TerminatedHandler service. |
177
|
|
|
* |
178
|
|
|
* @param Container $container The container |
179
|
|
|
* |
180
|
|
|
* @return void |
181
|
|
|
*/ |
182
|
|
|
public static function publishExitedHandler(Container $container): void |
183
|
|
|
{ |
184
|
|
|
$env = $container->getSingleton(Env::class); |
185
|
|
|
/** @var class-string<ExitedMiddleware>[] $middleware */ |
186
|
|
|
$middleware = $env::CLI_MIDDLEWARE_EXITED; |
187
|
|
|
|
188
|
|
|
$container->setSingleton( |
189
|
|
|
ExitedHandler::class, |
190
|
|
|
$handler = new Handler\ExitedHandler($container) |
191
|
|
|
); |
192
|
|
|
|
193
|
|
|
$handler->add(...$middleware); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
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