-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRouter.php
147 lines (129 loc) · 4.38 KB
/
Router.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/*
* This file is part of the Klipper package.
*
* (c) François Pluchino <francois.pluchino@klipper.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Klipper\Component\Routing;
use Klipper\Component\HttpFoundation\Util\RequestUtil;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Router as BaseRouter;
use Symfony\Component\Routing\RouterInterface;
/**
* @author François Pluchino <francois.pluchino@klipper.dev>
*/
class Router implements RouterInterface, RequestMatcherInterface
{
protected BaseRouter $router;
public function __construct(BaseRouter $router)
{
$this->router = $router;
}
public function setContext(RequestContext $context): void
{
$this->router->setContext($context);
}
public function getContext(): RequestContext
{
return $this->router->getContext();
}
public function matchRequest(Request $request): array
{
return $this->router->matchRequest($request);
}
public function getRouteCollection(): RouteCollection
{
return $this->router->getRouteCollection();
}
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
{
$path = rtrim($this->router->generate($name, $parameters, $referenceType), '/');
return RequestUtil::restoreFakeHost($path);
}
public function match(string $pathinfo): array
{
return $this->router->match($pathinfo);
}
/**
* Sets options.
*
* Available options:
*
* * cache_dir: The cache directory (or null to disable caching)
* * debug: Whether to enable debugging or not (false by default)
* * generator_class: The name of a UrlGeneratorInterface implementation
* * generator_dumper_class: The name of a GeneratorDumperInterface implementation
* * matcher_class: The name of a UrlMatcherInterface implementation
* * matcher_dumper_class: The name of a MatcherDumperInterface implementation
* * resource_type: Type hint for the main resource (optional)
* * strict_requirements: Configure strict requirement checking for generators
* implementing ConfigurableRequirementsInterface (default is true)
*
* @param array $options An array of options
*
* @throws \InvalidArgumentException When unsupported option is provided
*/
public function setOptions(array $options): void
{
$this->router->setOptions($options);
}
/**
* Sets an option.
*
* @param string $key The key
* @param mixed $value The value
*
* @throws \InvalidArgumentException
*/
public function setOption(string $key, $value): void
{
$this->router->setOption($key, $value);
}
/**
* Gets an option value.
*
* @param string $key The key
*
* @return mixed The value
*
* @throws \InvalidArgumentException
*/
public function getOption(string $key)
{
return $this->router->getOption($key);
}
/**
* Gets the UrlMatcher instance associated with this Router.
*
* @return UrlMatcherInterface A UrlMatcherInterface instance
*/
public function getMatcher(): UrlMatcherInterface
{
return $this->router->getMatcher();
}
/**
* Gets the UrlGenerator instance associated with this Router.
*
* @return UrlGeneratorInterface A UrlGeneratorInterface instance
*/
public function getGenerator(): UrlGeneratorInterface
{
return $this->router->getGenerator();
}
/**
* @param ExpressionFunctionProviderInterface $provider The expression function provider
*/
public function addExpressionLanguageProvider(ExpressionFunctionProviderInterface $provider): void
{
$this->router->addExpressionLanguageProvider($provider);
}
}