|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Lit\Bolt; |
|
6
|
|
|
|
|
7
|
|
|
use Lit\Air\Configurator as C; |
|
8
|
|
|
use Lit\Voltage\Interfaces\RouterInterface; |
|
9
|
|
|
use Lit\Voltage\RouterDispatchHandler; |
|
10
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
|
11
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Configuration class for typical app using router. |
|
15
|
|
|
*/ |
|
16
|
|
|
class RouterConfiguration |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* configuration for typical app using router |
|
20
|
|
|
* |
|
21
|
|
|
* @param mixed $router The router configuration. |
|
22
|
|
|
* @return array |
|
23
|
|
|
*/ |
|
24
|
2 |
|
public static function default($router = null): array |
|
25
|
|
|
{ |
|
26
|
|
|
$config = [ |
|
27
|
2 |
|
BoltApp::class => C::produce(BoltApp::class, [ |
|
28
|
2 |
|
RequestHandlerInterface::class => C::alias(BoltApp::class, 'handler'), |
|
29
|
2 |
|
MiddlewareInterface::class => C::alias(BoltApp::class, 'middleware'), |
|
30
|
|
|
]), |
|
31
|
2 |
|
C::join(BoltApp::class, 'handler') => C::instance(RouterDispatchHandler::class, [ |
|
32
|
2 |
|
RouterInterface::class => C::alias(BoltApp::class, 'handler', 'router'), |
|
33
|
|
|
]), |
|
34
|
2 |
|
C::join(BoltApp::class, 'middleware') => null, |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
2 |
|
if ($router === null) { |
|
38
|
|
|
@trigger_error('$router argument will become required', E_USER_DEPRECATED); |
|
39
|
|
|
} else { |
|
40
|
2 |
|
$config[C::join(BoltApp::class, 'handler', 'router')] = $router; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
2 |
|
return $config; |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|