module-yii2
module-yii2 copied to clipboard
if [yii\filters\ContentNegotiator] is in `bootstrap` it does not work
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
- Move Request making to L345 and remove L355-L363 entirely
yii\filters\ContentNegotiator::bootstrap()should only register eventHandler onyii\base\ApplicationonbeforeActionevent and handle it's ownyii\filters\ContentNegotiator::beforeAction()
I'd go way 1 since that's not touching framework itself. Do you have time for implementation?
We cannot remove L355-L363 since they are actually needed.
What we could theoretically do is intercept component creation:
- Get the original component definition for the request component, can be an array or a closure.
- 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.