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

Class-Handlers Support #15

Closed
antonio-gg-dev opened this issue Apr 20, 2023 · 3 comments
Closed

Class-Handlers Support #15

antonio-gg-dev opened this issue Apr 20, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@antonio-gg-dev
Copy link
Member

Should we support handlers being classes as well as functions? This would allow developers to encapsulate error handling or even group them by modules.

Handlers would end up being similar to controllers.

Perhaps in a future iteration we could even allow dependency injection to them, also just like controllers 🤔.

@antonio-gg-dev
Copy link
Member Author

antonio-gg-dev commented Apr 20, 2023

In addition, in the PR #14 implementation I had to do a little workaround to be able to encapsulate the built-in handlers in classes 😅.

private function addBuiltInHandlers(): void
{
$this->handle(
NotFound404Exception::class,
static fn (NotFound404Exception $exception) => (new NotFound404ExceptionHandler())->__invoke($exception),
);
$this->handle(
Exception::class,
static fn (Exception $exception) => (new FallbackExceptionHandler())->__invoke($exception),
);
}

@Chemaclass
Copy link
Member

I got an idea how to do this. I will create a PR soonish 🏃🏼

@Chemaclass
Copy link
Member

Implemented here: #16

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

No branches or pull requests

3 participants