public function matches(RequestInterface $request): ?RouteMatchInterface
    {
        $path = $request->getUrl()->getPath();
        $directoryParts = $path->getDirectoryParts();
        $filename = $path->getFilename() ?? '';

        if (count($this->path) === 0) {
            // My path is empty, i.e. should only match root path.
            if (count($directoryParts) !== 0) {
                return null;
            }

            return new RouteMatch($this->getControllerClassName(), $filename);
        }

        if (count($this->path) > count($directoryParts)) {
            // My path contains more than the path in request, e.g. path /foo/ should not match /bar
            return null;
        }

        // Check each parts.
        $index = 0;
        foreach ($this->path as $pathPart) {
            // Part of path does not match.
            if ($pathPart !== $directoryParts[$index]) {
                return null;
            }

            $index++;
        }

        if (count($directoryParts) > $index) {
            $action = $directoryParts[$index];
            $parameters = array_slice($directoryParts, $index + 1);
            $parameters[] = $filename;
        } else {
            $action = $filename;
            $parameters = [];
        }

        return new RouteMatch($this->getControllerClassName(), $action, $parameters);
    }