1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Xervice\Routing; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use DataProvider\RoutingContextDataProvider; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
use Symfony\Component\Routing\Matcher\UrlMatcher; |
10
|
|
|
use Symfony\Component\Routing\RequestContext; |
11
|
|
|
use Symfony\Component\Routing\RouteCollection as SymfonyRouteCollection; |
12
|
|
|
use Xervice\Core\Factory\AbstractFactory; |
13
|
|
|
use Xervice\Routing\Business\Matcher\MatchProvider; |
14
|
|
|
use Xervice\Routing\Business\Matcher\MatchProviderInterface; |
15
|
|
|
use Xervice\Routing\Business\Route\RouteCollection; |
16
|
|
|
use Xervice\Routing\Business\Route\RouteCollectionInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @method \Xervice\Routing\RoutingConfig getConfig() |
20
|
|
|
*/ |
21
|
|
|
class RoutingFactory extends AbstractFactory |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var \Xervice\Routing\Business\Route\RouteCollectionInterface |
25
|
|
|
*/ |
26
|
|
|
private $routeCollection; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return \Xervice\Routing\Business\Matcher\MatchProvider |
30
|
|
|
*/ |
31
|
3 |
|
public function createMatcher(): MatchProviderInterface |
32
|
|
|
{ |
33
|
3 |
|
return new MatchProvider( |
34
|
3 |
|
$this->createUrlMatcher(), |
35
|
3 |
|
$this->createRequest() |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return \Symfony\Component\Routing\Matcher\UrlMatcher |
41
|
|
|
*/ |
42
|
3 |
|
public function createUrlMatcher(): UrlMatcher |
43
|
|
|
{ |
44
|
3 |
|
return new UrlMatcher( |
45
|
3 |
|
$this->getRouteCollection()->getRouteCollection(), |
46
|
3 |
|
$this->createRequestContext() |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \Symfony\Component\Routing\RequestContext |
52
|
|
|
*/ |
53
|
3 |
|
public function createRequestContext(): RequestContext |
54
|
|
|
{ |
55
|
3 |
|
$context = new RequestContext(); |
56
|
3 |
|
$context->fromRequest( |
57
|
3 |
|
$this->createRequest() |
58
|
|
|
); |
59
|
|
|
|
60
|
3 |
|
return $context; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return \Symfony\Component\HttpFoundation\Request |
65
|
|
|
*/ |
66
|
3 |
|
public function createRequest(): Request |
67
|
|
|
{ |
68
|
3 |
|
return Request::createFromGlobals(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return \DataProvider\RoutingContextDataProvider |
73
|
|
|
*/ |
74
|
|
|
public function createContext(): RoutingContextDataProvider |
75
|
|
|
{ |
76
|
|
|
return (new RoutingContextDataProvider())->setContext( |
77
|
|
|
$this->getConfig()->getContext() |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return \Xervice\Routing\Business\Route\RouteCollectionInterface |
83
|
|
|
*/ |
84
|
1 |
|
public function createRouteCollection(): RouteCollectionInterface |
85
|
|
|
{ |
86
|
1 |
|
return new RouteCollection( |
87
|
1 |
|
new SymfonyRouteCollection() |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return \Xervice\Routing\Business\Route\RouteCollectionInterface |
93
|
|
|
*/ |
94
|
3 |
|
public function getRouteCollection(): RouteCollectionInterface |
95
|
|
|
{ |
96
|
3 |
|
if ($this->routeCollection === null) { |
97
|
1 |
|
$this->routeCollection = $this->createRouteCollection(); |
98
|
|
|
} |
99
|
|
|
|
100
|
3 |
|
return $this->routeCollection; |
101
|
|
|
} |
102
|
|
|
} |