0 follower

Final Class Yiisoft\Router\FastRoute\UrlMatcher

InheritanceYiisoft\Router\FastRoute\UrlMatcher
ImplementsYiisoft\Router\UrlMatcherInterface

Public Methods

Hide inherited 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

Hide inherited 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

Hide inherited methods

__construct() public method

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();
}

            
match() public method

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);
}