Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hello, I wanted to see if there's a better way to return a response when a ControllerEvent or ControllerArgumentsEvent is being dispatched, as neither of them can contain a new explicit response.

We currently throw a specific exception and then catch it with ExceptionEvent to set a response there. While this works, I'd prefer not to throw the exception if not needed.

Is there a better way to handle this? I don't have the information I need until ControllerArgumentsEvent, so there's that.

Any chance that responses could be added to ControllerEvent and ControllerArgumentsEvent in the future? Seems like it should be easy to do.

You must be logged in to vote

Replies: 1 comment

Comment options

Hello,
since those events have a setController method you can simply call it with a callable returning your response (and then stop the event propagation). This is how the CacheAttributeListener does it:

$event->setController(static fn () => $response);
$event->stopPropagation();

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.