|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Obsidian\Routing; |
|
4
|
|
|
|
|
5
|
|
|
use Obsidian\Framework; |
|
6
|
|
|
use Obsidian\ServiceProviders\ServiceProviderInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Provide routing dependencies |
|
10
|
|
|
* |
|
11
|
|
|
* @codeCoverageIgnore |
|
12
|
|
|
*/ |
|
13
|
|
|
class RoutingServiceProvider implements ServiceProviderInterface { |
|
14
|
|
|
/** |
|
15
|
|
|
* Key=>Class dictionary of condition types |
|
16
|
|
|
* |
|
17
|
|
|
* @var string[string] |
|
18
|
|
|
*/ |
|
19
|
|
|
protected static $condition_classes = [ |
|
20
|
|
|
'url' => \Obsidian\Routing\Conditions\Url::class, |
|
21
|
|
|
'custom' => \Obsidian\Routing\Conditions\Custom::class, |
|
22
|
|
|
'multiple' => \Obsidian\Routing\Conditions\Multiple::class, |
|
23
|
|
|
'post_id' => \Obsidian\Routing\Conditions\PostId::class, |
|
24
|
|
|
'post_slug' => \Obsidian\Routing\Conditions\PostSlug::class, |
|
25
|
|
|
'post_template' => \Obsidian\Routing\Conditions\PostTemplate::class, |
|
26
|
|
|
'post_type' => \Obsidian\Routing\Conditions\PostType::class, |
|
27
|
|
|
'query_var' => \Obsidian\Routing\Conditions\QueryVar::class, |
|
28
|
|
|
'has_query_var' => \Obsidian\Routing\Conditions\HasQueryVar::class, |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritDoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
public function register( $container ) { |
|
35
|
|
|
$container['framework.config'] = array_merge( [ |
|
36
|
|
|
'global_middleware' => [], |
|
37
|
|
|
], $container['framework.config'] ); |
|
38
|
|
|
|
|
39
|
|
|
$container['framework.routing.global_middleware'] = $container['framework.config']['global_middleware']; |
|
40
|
|
|
$container['framework.routing.global_middleware'] = apply_filters( |
|
41
|
|
|
'obsidian_global_middleware', |
|
42
|
|
|
$container['framework.routing.global_middleware'] |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
foreach ( static::$condition_classes as $key => $class ) { |
|
46
|
|
|
$container[ 'framework.routing.conditions.' . $key ] = $class; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$container['framework.routing.router'] = function() { |
|
50
|
|
|
return new \Obsidian\Routing\Router(); |
|
51
|
|
|
}; |
|
52
|
|
|
|
|
53
|
|
|
Framework::facade( 'Router', \Obsidian\Routing\RouterFacade::class ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritDoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function boot( $container ) { |
|
60
|
|
|
\Router::boot(); // facade |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|