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
|
|
|
|