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

if [yii\filters\ContentNegotiator] is in bootstrap it does not work #101

Open
mikk150 opened this issue May 8, 2024 · 2 comments
Open

Comments

@mikk150
Copy link

mikk150 commented May 8, 2024

IF I want to use yii\filters\ContentNegotiator in bootstrap(as it implements yii\base\BootstrapInterface and therefore I should be able to do so)

It unfortunately does not work as

Therefore it does not work

There are 2 solutions how to fix it

  1. Move Request making to L345 and remove L355-L363 entirely
  2. yii\filters\ContentNegotiator::bootstrap() should only register eventHandler on yii\base\Application on beforeAction event and handle it's own yii\filters\ContentNegotiator::beforeAction()
@samdark
Copy link
Member

samdark commented May 9, 2024

I'd go way 1 since that's not touching framework itself. Do you have time for implementation?

@SamMousa
Copy link
Collaborator

We cannot remove L355-L363 since they are actually needed.

What we could theoretically do is intercept component creation:

  1. Get the original component definition for the request component, can be an array or a closure.
  2. Replace it with a closure that resolves the original definition and then initializes the request content like currently done in L355-363.

We have a hard time cleanly integrating because both the application as well as the request might be custom classes.

Also, in general using application bootstrap will lead to weird behavior since by default we don't recreate the application before each request. My personal opinion is that you should not interact with the request in the application bootstrap phase. But your argument that this should be possible (since ContentNegotiator does it) is also valid.

This means that if inside 1 test you do 2 requests the bootstrap code will only run once. And in the case of ContentNegotiator will probably set your application language based on the first request only.

tldr; this will be hard to fix.

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

No branches or pull requests

3 participants