Skip to content

Remove dep with symfony/http-kernel#135

Closed
jissereitsma wants to merge 1 commit intomagewirephp:mainfrom
jissereitsma:patch-1
Closed

Remove dep with symfony/http-kernel#135
jissereitsma wants to merge 1 commit intomagewirephp:mainfrom
jissereitsma:patch-1

Conversation

@jissereitsma
Copy link
Copy Markdown
Contributor

As mentioned in #107 there is an undocumented dependency with symfony/http-kernel only for an exception that is thrown. The HttpException (https://github.com/symfony/http-kernel/blob/6.3/Exception/HttpException.php) actually inherits from \RuntimeException. This PR simply just removes the dep and throws the RuntimeException as is. Nothing fancy.

Additional comment, the reason why this issue got started is that the symfony/http-foundation package (which is a requirement for Magewire) has a require-dev dep with symfony/http-kernel (https://github.com/symfony/http-foundation/blob/6.3/composer.json#L29). If composer is installed in dev env, then this problem does not occur.

$request = $this->httpFactory->createRequest($this->request->getParams())->isSubsequent(true);
} catch (LocalizedException $exception) {
throw new HttpException(400);
throw new RuntimeException(400);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this should be merged into the core. \RuntimeException's first arg requires a message and the second a exception code. The reason having the HttpException is not having to pass in each status message for simple 400, 404, 503 etc. Those are all default and will be rendered in the frontend.

Also, having the right status code is also important in the frontend.

Is there something I'm overlooking?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you spotted a mistake I made. Having the HTTP status code available is indeed a requirement I missed. However, adding a composer package for this seems a bit much. One option could be to simply create a duplicate HttpException class in the magewire package (and then drop the dependency with symfony/http-kernel). Another option could be to simply refactor the code in the controller a bit further - the HttpException class is used only once as an argument to throwException($exception). The HTTP status code could easily be turned into an optional second argument (throwException($exception, $statusCode = null). Which option do you think is better? Happy to refactor this PR.

@wpoortman wpoortman closed this Jun 2, 2025
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