Passed
Push — master ( 0000a3...2b10f1 )
by Melech
01:30
created

publishCheckForHelpOptionsMiddleware()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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 Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Valkyrja\Application\Env\Env;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Application\Env\Env was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Valkyrja\Cli\Interaction\Data\Config;
19
use Valkyrja\Cli\Middleware\Contract\ExitedMiddlewareContract;
20
use Valkyrja\Cli\Middleware\Contract\InputReceivedMiddlewareContract;
21
use Valkyrja\Cli\Middleware\Contract\RouteDispatchedMiddlewareContract;
22
use Valkyrja\Cli\Middleware\Contract\RouteMatchedMiddlewareContract;
23
use Valkyrja\Cli\Middleware\Contract\RouteNotMatchedMiddlewareContract;
24
use Valkyrja\Cli\Middleware\Contract\ThrowableCaughtMiddlewareContract;
25
use Valkyrja\Cli\Middleware\Handler\Contract\ExitedHandlerContract;
26
use Valkyrja\Cli\Middleware\Handler\Contract\InputReceivedHandlerContract;
27
use Valkyrja\Cli\Middleware\Handler\Contract\RouteDispatchedHandlerContract;
28
use Valkyrja\Cli\Middleware\Handler\Contract\RouteMatchedHandlerContract;
29
use Valkyrja\Cli\Middleware\Handler\Contract\RouteNotMatchedHandlerContract;
30
use Valkyrja\Cli\Middleware\Handler\Contract\ThrowableCaughtHandlerContract;
31
use Valkyrja\Cli\Middleware\Handler\ExitedHandler;
32
use Valkyrja\Cli\Middleware\Handler\InputReceivedHandler;
33
use Valkyrja\Cli\Middleware\Handler\RouteDispatchedHandler;
34
use Valkyrja\Cli\Middleware\Handler\RouteMatchedHandler;
35
use Valkyrja\Cli\Middleware\Handler\RouteNotMatchedHandler;
36
use Valkyrja\Cli\Middleware\Handler\ThrowableCaughtHandler;
37
use Valkyrja\Cli\Middleware\InputReceived\CheckForHelpOptionsMiddleware;
38
use Valkyrja\Cli\Middleware\InputReceived\CheckForVersionOptionsMiddleware;
39
use Valkyrja\Cli\Middleware\InputReceived\CheckGlobalInteractionOptionsMiddleware;
40
use Valkyrja\Container\Manager\Contract\ContainerContract;
41
use Valkyrja\Container\Provider\Provider;
42
43
final class ServiceProvider extends Provider
44
{
45
    /**
46
     * @inheritDoc
47
     */
48
    #[Override]
49
    public static function publishers(): array
50
    {
51
        return [
52
            InputReceivedHandlerContract::class            => [self::class, 'publishInputReceivedHandler'],
53
            ThrowableCaughtHandlerContract::class          => [self::class, 'publishThrowableCaughtHandler'],
54
            RouteMatchedHandlerContract::class             => [self::class, 'publishRouteMatchedHandler'],
55
            RouteNotMatchedHandlerContract::class          => [self::class, 'publishRouteNotMatchedHandler'],
56
            RouteDispatchedHandlerContract::class          => [self::class, 'publishRouteDispatchedHandler'],
57
            ExitedHandlerContract::class                   => [self::class, 'publishExitedHandler'],
58
            CheckForHelpOptionsMiddleware::class           => [self::class, 'publishCheckForHelpOptionsMiddleware'],
59
            CheckForVersionOptionsMiddleware::class        => [self::class, 'publishCheckForVersionOptionsMiddleware'],
60
            CheckGlobalInteractionOptionsMiddleware::class => [self::class, 'publishCheckGlobalInteractionOptionsMiddleware'],
61
        ];
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67
    #[Override]
68
    public static function provides(): array
69
    {
70
        return [
71
            InputReceivedHandlerContract::class,
72
            RouteDispatchedHandlerContract::class,
73
            ThrowableCaughtHandlerContract::class,
74
            RouteMatchedHandlerContract::class,
75
            RouteNotMatchedHandlerContract::class,
76
            ExitedHandlerContract::class,
77
            CheckForHelpOptionsMiddleware::class,
78
            CheckForVersionOptionsMiddleware::class,
79
            CheckGlobalInteractionOptionsMiddleware::class,
80
        ];
81
    }
82
83
    /**
84
     * Publish the RequestReceivedHandler service.
85
     *
86
     * @param ContainerContract $container The container
87
     *
88
     * @return void
89
     */
90
    public static function publishInputReceivedHandler(ContainerContract $container): void
91
    {
92
        $env = $container->getSingleton(Env::class);
93
        /** @var class-string<InputReceivedMiddlewareContract>[] $middleware */
94
        $middleware = $env::CLI_MIDDLEWARE_INPUT_RECEIVED;
95
96
        $container->setSingleton(
97
            InputReceivedHandlerContract::class,
98
            $handler = new InputReceivedHandler($container)
99
        );
100
101
        $handler->add(...$middleware);
102
    }
103
104
    /**
105
     * Publish the RouteDispatchedHandler service.
106
     *
107
     * @param ContainerContract $container The container
108
     *
109
     * @return void
110
     */
111
    public static function publishRouteDispatchedHandler(ContainerContract $container): void
112
    {
113
        $env = $container->getSingleton(Env::class);
114
        /** @var class-string<RouteDispatchedMiddlewareContract>[] $middleware */
115
        $middleware = $env::CLI_MIDDLEWARE_COMMAND_DISPATCHED;
116
117
        $container->setSingleton(
118
            RouteDispatchedHandlerContract::class,
119
            $handler = new RouteDispatchedHandler($container)
120
        );
121
122
        $handler->add(...$middleware);
123
    }
124
125
    /**
126
     * Publish the ThrowableCaughtHandler service.
127
     *
128
     * @param ContainerContract $container The container
129
     *
130
     * @return void
131
     */
132
    public static function publishThrowableCaughtHandler(ContainerContract $container): void
133
    {
134
        $env = $container->getSingleton(Env::class);
135
        /** @var class-string<ThrowableCaughtMiddlewareContract>[] $middleware */
136
        $middleware = $env::CLI_MIDDLEWARE_THROWABLE_CAUGHT;
137
138
        $container->setSingleton(
139
            ThrowableCaughtHandlerContract::class,
140
            $handler = new ThrowableCaughtHandler($container)
141
        );
142
143
        $handler->add(...$middleware);
144
    }
145
146
    /**
147
     * Publish the RouteMatchedHandler service.
148
     *
149
     * @param ContainerContract $container The container
150
     *
151
     * @return void
152
     */
153
    public static function publishRouteMatchedHandler(ContainerContract $container): void
154
    {
155
        $env = $container->getSingleton(Env::class);
156
        /** @var class-string<RouteMatchedMiddlewareContract>[] $middleware */
157
        $middleware = $env::CLI_MIDDLEWARE_COMMAND_MATCHED;
158
159
        $container->setSingleton(
160
            RouteMatchedHandlerContract::class,
161
            $handler = new RouteMatchedHandler($container)
162
        );
163
164
        $handler->add(...$middleware);
165
    }
166
167
    /**
168
     * Publish the RouteNotMatchedHandler service.
169
     *
170
     * @param ContainerContract $container The container
171
     *
172
     * @return void
173
     */
174
    public static function publishRouteNotMatchedHandler(ContainerContract $container): void
175
    {
176
        $env = $container->getSingleton(Env::class);
177
        /** @var class-string<RouteNotMatchedMiddlewareContract>[] $middleware */
178
        $middleware = $env::CLI_MIDDLEWARE_COMMAND_NOT_MATCHED;
179
180
        $container->setSingleton(
181
            RouteNotMatchedHandlerContract::class,
182
            $handler = new RouteNotMatchedHandler($container)
183
        );
184
185
        $handler->add(...$middleware);
186
    }
187
188
    /**
189
     * Publish the TerminatedHandler service.
190
     *
191
     * @param ContainerContract $container The container
192
     *
193
     * @return void
194
     */
195
    public static function publishExitedHandler(ContainerContract $container): void
196
    {
197
        $env = $container->getSingleton(Env::class);
198
        /** @var class-string<ExitedMiddlewareContract>[] $middleware */
199
        $middleware = $env::CLI_MIDDLEWARE_EXITED;
200
201
        $container->setSingleton(
202
            ExitedHandlerContract::class,
203
            $handler = new ExitedHandler($container)
204
        );
205
206
        $handler->add(...$middleware);
207
    }
208
209
    /**
210
     * Publish the CheckForHelpOptionsMiddleware service.
211
     */
212
    public static function publishCheckForHelpOptionsMiddleware(ContainerContract $container): void
213
    {
214
        $container->setSingleton(
215
            CheckForHelpOptionsMiddleware::class,
216
            new CheckForHelpOptionsMiddleware(
217
                env: $container->getSingleton(Env::class)
218
            )
219
        );
220
    }
221
222
    /**
223
     * Publish the CheckForVersionOptionsMiddleware service.
224
     */
225
    public static function publishCheckForVersionOptionsMiddleware(ContainerContract $container): void
226
    {
227
        $container->setSingleton(
228
            CheckForVersionOptionsMiddleware::class,
229
            new CheckForVersionOptionsMiddleware(
230
                env: $container->getSingleton(Env::class)
231
            )
232
        );
233
    }
234
235
    /**
236
     * Publish the CheckGlobalInteractionOptionsMiddleware service.
237
     */
238
    public static function publishCheckGlobalInteractionOptionsMiddleware(ContainerContract $container): void
239
    {
240
        $container->setSingleton(
241
            CheckGlobalInteractionOptionsMiddleware::class,
242
            new CheckGlobalInteractionOptionsMiddleware(
243
                config: $container->getSingleton(Config::class),
244
                env: $container->getSingleton(Env::class)
245
            )
246
        );
247
    }
248
}
249