Some improvements and comments in preparation of multi-segment slugs

This commit is contained in:
Alejandro Celaya
2022-07-29 17:02:00 +02:00
parent d375dece0e
commit e0e511f56d
5 changed files with 18 additions and 15 deletions

View File

@@ -13,21 +13,21 @@ use function rtrim;
class NotFoundType
{
private function __construct(private readonly VisitType $type)
private function __construct(private readonly ?VisitType $type)
{
}
public static function fromRequest(ServerRequestInterface $request, string $basePath): self
{
/** @var RouteResult $routeResult */
$routeResult = $request->getAttribute(RouteResult::class, RouteResult::fromRouteFailure(null));
$routeResult = $request->getAttribute(RouteResult::class) ?? RouteResult::fromRouteFailure(null);
$isBaseUrl = rtrim($request->getUri()->getPath(), '/') === $basePath;
$type = match (true) {
$isBaseUrl => VisitType::BASE_URL,
$routeResult->isFailure() => VisitType::REGULAR_404,
$routeResult->getMatchedRouteName() === RedirectAction::class => VisitType::INVALID_SHORT_URL,
default => VisitType::VALID_SHORT_URL,
default => null,
};
return new self($type);