Final Class Yiisoft\Router\FastRoute\UrlMatcher
| Inheritance | Yiisoft\Router\FastRoute\UrlMatcher |
|---|---|
| Implements | Yiisoft\Router\UrlMatcherInterface |
Psalm Types
| Name | Value |
|---|---|
| ResultNotFound | array{0: 0} |
| ResultMethodNotAllowed | array{0: 2, 1: string[]} |
| ResultFound | array{0: 1, 1: string, 2: array<string, string>} |
| DispatcherCallback | callable |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Accepts optionally a FastRoute RouteCollector and a callable factory that can return a FastRoute dispatcher. | Yiisoft\Router\FastRoute\UrlMatcher |
| match() | Yiisoft\Router\FastRoute\UrlMatcher |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| CONFIG_CACHE_KEY | 'cache_key' | Configuration key used to set the cache file path. | Yiisoft\Router\FastRoute\UrlMatcher |
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 ( \Yiisoft\Router\RouteCollectionInterface $routeCollection, \Psr\SimpleCache\CacheInterface|null $cache = null, array|null $config = null, \FastRoute\RouteCollector|null $fastRouteCollector = null, callable|null $dispatcherFactory = null ) | ||
| $routeCollection | \Yiisoft\Router\RouteCollectionInterface | |
| $cache | \Psr\SimpleCache\CacheInterface|null | |
| $config | array|null |
Array of custom configuration options. |
| $fastRouteCollector | \FastRoute\RouteCollector|null |
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 \Yiisoft\Router\MatchingResult match ( \Psr\Http\Message\ServerRequestInterface $request ) | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
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);
}
Signup or Login in order to comment.