src/Viserio/Component/Routing/Dispatcher/SimpleDispatcher.php
public function handle(RouteCollectionContract $routes, ServerRequestInterface $request): ResponseInterface
    {
        $cacheFile = $this->getCachePath();
        $dir       = \pathinfo($cacheFile, \PATHINFO_DIRNAME);

        if ($this->refreshCache === true || ! \file_exists($cacheFile)) {
            self::generateDirectory($dir);

            $this->generateRouterFile($routes);
        }

        $router = require $cacheFile;

        $match = $router(\strtoupper($request->getMethod()), $this->prepareUriPath($request->getUri()->getPath()));

        if ($match[0] === self::FOUND) {
            return $this->handleFound($routes, $request, $match[1], $match[2]);
        }

        $requestPath = '/' . \ltrim($request->getUri()->getPath(), '/');

        if ($match[0] === self::HTTP_METHOD_NOT_ALLOWED) {
            throw new MethodNotAllowedException(\sprintf(
                '405 Method [%s] Not Allowed: For requested route [%s].',
                \implode(',', $match[1]),
                $requestPath
            ));
        }

        throw new NotFoundException(\sprintf(
            '404 Not Found: Requested route [%s].',
            $requestPath
        ));
    }
public function handle(RouteCollectionContract $routes, ServerRequestInterface $request): ResponseInterface
    {
        $cacheFile = $this->getCachePath();
        $dir       = \pathinfo($cacheFile, \PATHINFO_DIRNAME);

        if ($this->refreshCache === true || ! \file_exists($cacheFile)) {
            self::generateDirectory($dir);

            $this->generateRouterFile($routes);
        }

        $router = require $cacheFile;

        $match = $router(\strtoupper($request->getMethod()), $this->prepareUriPath($request->getUri()->getPath()));

        if ($match[0] === self::FOUND) {
            return $this->handleFound($routes, $request, $match[1], $match[2]);
        }

        $requestPath = '/' . \ltrim($request->getUri()->getPath(), '/');

        if ($match[0] === self::HTTP_METHOD_NOT_ALLOWED) {
            throw new MethodNotAllowedException(\sprintf(
                '405 Method [%s] Not Allowed: For requested route [%s].',
                \implode(',', $match[1]),
                $requestPath
            ));
        }

        throw new NotFoundException(\sprintf(
            '404 Not Found: Requested route [%s].',
            $requestPath
        ));
    }
{@inheritdoc}