-
Notifications
You must be signed in to change notification settings - Fork 65
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
Preparation for immutable objects #116
Comments
Hmm, looks like you're trying to tell the injector to, when it encounters an instance of This way your implementation doesn't know about the injector.
Just a suggestion. This might not work for you as it'll need to be in the same context as where you get the An alternative would be to grab the injector in the |
This is a sane use-case. There are a couple of options to "fix" This would be safe for BC as the return value from prepares wasn't previously meaningful. Can anyone think of any drawbacks to that approach that I may be missing? Using a delegate like @J7mbo suggested would work, but I try to avoid being forced to instantiate closures when possible in favor of string class method constructions just to make sure things load as lazily as possible (the closure may not always be needed for the particular application resource being loaded). This would change the OP code to: $injector->prepare('Zend\Diactoros\Response', function ($response) {
return $response->withHeader('X-API-Version', 'v2.1');
}); |
@rdlowrey I like that solution very much. Using |
Okay, great. I'll try to implement/test/tag that change today. Will post updates here as they happen. |
The |
I've pushed the mentioned change up to master. @shadowhand if you can confirm that works as you expect (you can probably just verify by looking at the new test cases) I will go ahead and tag 1.1.0 |
This capability is available as of 1.1.0 |
👍 |
Right now it is not possible to modify an immutable object using
prepare
. For instance, I might want to do this (as a contrived example):Attempting this will currently produce the following error:
Warning: Parameter 1 to {closure}() expected to be a reference, value given
Because reflection is used to execute the closure, it is not possible to use references.
What is the best way to handle immutable preparation?
The text was updated successfully, but these errors were encountered: