Passed
Pull Request — master (#33)
by Melech
03:28
created

MessageRouterServiceProvider::publishRouter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 16
rs 9.8333
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\Routing\Providers;
15
16
use Valkyrja\Config\Config\Config;
17
use Valkyrja\Container\Container;
18
use Valkyrja\Container\Support\Provider;
19
use Valkyrja\Dispatcher\Dispatcher;
20
use Valkyrja\Event\Events;
21
use Valkyrja\Http\ResponseFactory;
22
use Valkyrja\Routing\Collection;
23
use Valkyrja\Routing\Dispatchers\MessageCapableRouter;
24
use Valkyrja\Routing\Matcher;
25
use Valkyrja\Routing\Router;
26
use Valkyrja\Validation\Validator;
27
28
/**
29
 * Class MessageRouterServiceProvider.
30
 *
31
 * @author Melech Mizrachi
32
 */
33
class MessageRouterServiceProvider extends Provider
34
{
35
    /**
36
     * @inheritDoc
37
     */
38
    public static function publishers(): array
39
    {
40
        return [
41
            Router::class => 'publishRouter',
42
        ];
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public static function provides(): array
49
    {
50
        return [
51
            Router::class,
52
        ];
53
    }
54
55
    /**
56
     * Publish the router service.
57
     *
58
     * @param Container $container The container
59
     *
60
     * @return void
61
     */
62
    public static function publishRouter(Container $container): void
63
    {
64
        $config = $container->getSingleton(Config::class);
65
66
        $container->setSingleton(
67
            Router::class,
68
            new MessageCapableRouter(
69
                $container->getSingleton(Validator::class),
70
                $container->getSingleton(Collection::class),
71
                $container->getSingleton(Container::class),
72
                $container->getSingleton(Dispatcher::class),
73
                $container->getSingleton(Events::class),
74
                $container->getSingleton(Matcher::class),
75
                $container->getSingleton(ResponseFactory::class),
76
                $config['routing'],
77
                $config['app']['debug']
78
            )
79
        );
80
    }
81
}
82