Final Class Yiisoft\Router\FastRoute\UrlMatcher
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Accepts optionally a FastRoute RouteCollector and a callable factory that can return a FastRoute dispatcher. | Yiisoft\ |
| match() | Yiisoft\ |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| CONFIG_CACHE_KEY | 'cache_key' | Configuration key used to set the cache file path. | Yiisoft\ |
Method Details
Accepts optionally a FastRoute RouteCollector and a callable factory that can return a FastRoute dispatcher.
If either is not provided defaults will be used:
- A RouteCollector instance will be created composing a RouteParser and RouteGenerator.
- A callable that returns a GroupCountBased dispatcher will be created.
| public mixed __construct ( \ | ||
| $routeCollection | \ |
|
| $cache | ?\ |
|
| $config | array|null |
Array of custom configuration options. |
| $fastRouteCollector | \ |
If not provided, a default implementation will be used. |
| $dispatcherFactory | callable|null |
Callable that will return a FastRoute dispatcher. |
public function __construct(
private readonly RouteCollectionInterface $routeCollection,
private readonly ?CacheInterface $cache = null,
?array $config = null,
?RouteCollector $fastRouteCollector = null,
?callable $dispatcherFactory = null,
) {
$this->fastRouteCollector = $fastRouteCollector ?? $this->createRouteCollector();
$this->dispatcherCallback = $dispatcherFactory;
$this->loadConfig($config);
$this->loadDispatchData();
}
| public \ | ||
| $request | \ |
|
public function match(ServerRequestInterface $request): MatchingResult
{
if (!$this->hasCache && !$this->hasInjectedRoutes) {
$this->injectRoutes();
}
$dispatchData = $this->getDispatchData();
$path = urldecode($request
->getUri()
->getPath());
$method = $request->getMethod();
/**
* @psalm-var ResultNotFound|ResultMethodNotAllowed|ResultFound $result
*/
$result = $this
->getDispatcher($dispatchData)
->dispatch($method, $request
->getUri()
->getHost() . $path);
/** @psalm-suppress ArgumentTypeCoercion Psalm can't determine correct type here */
return $result[0] !== Dispatcher::FOUND
? $this->marshalFailedRoute($result)
: $this->marshalMatchedRoute($result);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.