Passed
Branch master (372b2a)
by Filipe
01:32
created

DispatcherModule::middlewareHandlers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of web-stack
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\WebStack;
13
14
use Dotenv\Dotenv;
15
use Slick\ModuleApi\Infrastructure\AbstractModule;
16
use Slick\ModuleApi\Infrastructure\FrontController\MiddlewareHandler;
17
use Slick\ModuleApi\Infrastructure\FrontController\MiddlewarePosition;
0 ignored issues
show
Bug introduced by
The type Slick\ModuleApi\Infrastr...ller\MiddlewarePosition 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 Slick\ModuleApi\Infrastructure\FrontController\Position;
19
use Slick\ModuleApi\Infrastructure\FrontController\WebModuleInterface;
20
use Slick\ModuleApi\Infrastructure\SlickModuleInterface;
21
use Slick\WebStack\Infrastructure\DependencyContainerFactory;
22
use Slick\WebStack\Infrastructure\Http\DispatcherMiddleware;
0 ignored issues
show
Bug introduced by
The type Slick\WebStack\Infrastru...tp\DispatcherMiddleware 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...
23
use Slick\WebStack\Infrastructure\Http\RoutingMiddleware;
24
use function Slick\ModuleApi\importSettingsFile;
25
26
/**
27
 * DispatcherSlickModule
28
 *
29
 * @package Slick\WebStack
30
 */
31
final class DispatcherModule extends AbstractModule implements SlickModuleInterface, WebModuleInterface
32
{
33
    public function description(): ?string
34
    {
35
        return "Core module that integrates routing and dispatching features as middleware for a web application.";
36
    }
37
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public function services(): array
43
    {
44
        return require dirname(__DIR__) . '/config/routing.php';
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function settings(Dotenv $dotenv): array
51
    {
52
53
        $settingsFile = APP_ROOT .'/config/modules/dispatcher.php';
54
        $defaultSettings = [
55
            'router' => [
56
                'cache' => [
57
                    'enabled' => true,
58
                    'directory' => sys_get_temp_dir() . '/cache/routes',
59
                ],
60
                'resources_path' => APP_ROOT . '/src/UserInterface'
61
            ]
62
        ];
63
        return importSettingsFile($settingsFile, $defaultSettings);
64
    }
65
66
    /**
67
     * @inheritDoc
68
     */
69
    public function middlewareHandlers(): array
70
    {
71
        return [
72
            new MiddlewareHandler('router', new MiddlewarePosition(Position::Top), RoutingMiddleware::class),
73
            new MiddlewareHandler(
74
                'dispatcher',
75
                new MiddlewarePosition(Position::Before, 'default-response'),
76
                new DispatcherMiddleware(DependencyContainerFactory::instance()->container())
77
            ),
78
        ];
79
    }
80
}
81