Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base path returned for nonexistent route instead of throwing exception #45

Open
wants to merge 1 commit into
base: 5.17.x
Choose a base branch
from

Conversation

Jurj-Bogdan
Copy link

Q A
Documentation no
Bugfix no
BC Break yes
New Feature no
RFC no
QA no

Description

Invoking UrlHelper while on an invalid route will lead to a RuntimeException being thrown, which in the case of laminas/getlaminas.org will prevent the error page from being rendered altogether (as mentioned in #191 of getlaminas.org, which was the starting point for this PR).
In getlaminas' case, the exception is triggered by calling $this->url() in the navigation partial when accessing a nonexistent route.

One potential fix would be preventing this exception from being thrown and returning the valid base url, as implemented in this PR. However, it would be a BC break for anyone trusting this exception to be thrown.

There are multiple ways to fix this problem, in different repositories - maybe by handling the exception in mezzio/mezzio's NotFoundHandler, or in getlaminas.org itself. I am open to suggestions on how else to handle this issue.

@gsteel
Copy link
Member

gsteel commented Aug 12, 2024

This should be handled in the view layer.

Layouts and partials should take care not to generate URIs with invalid routing information, such as rendering a url for the current un-matched route.

This change effectively means - "If the matched route is a 404, then generate an invalid URI for the given parameters". Typically, $basePath will also be an empty string here.

I prefer the exception.

@gsteel
Copy link
Member

gsteel commented Aug 12, 2024

The linked navigation partial should be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants