{"action":"created","issue":{"url":"https://api.github.com/repos/rdlowrey/auryn/issues/116","labels_url":"https://api.github.com/repos/rdlowrey/auryn/issues/116/labels{/name}","comments_url":"https://api.github.com/repos/rdlowrey/auryn/issues/116/comments","events_url":"https://api.github.com/repos/rdlowrey/auryn/issues/116/events","html_url":"https://github.com/rdlowrey/auryn/issues/116","id":103177653,"number":116,"title":"Preparation for immutable objects","user":{"login":"shadowhand","id":38203,"avatar_url":"https://avatars.githubusercontent.com/u/38203?v=3","gravatar_id":"","url":"https://api.github.com/users/shadowhand","html_url":"https://github.com/shadowhand","followers_url":"https://api.github.com/users/shadowhand/followers","following_url":"https://api.github.com/users/shadowhand/following{/other_user}","gists_url":"https://api.github.com/users/shadowhand/gists{/gist_id}","starred_url":"https://api.github.com/users/shadowhand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shadowhand/subscriptions","organizations_url":"https://api.github.com/users/shadowhand/orgs","repos_url":"https://api.github.com/users/shadowhand/repos","events_url":"https://api.github.com/users/shadowhand/events{/privacy}","received_events_url":"https://api.github.com/users/shadowhand/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-26T05:33:28Z","updated_at":"2015-08-26T09:58:20Z","closed_at":null,"body":"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):\r\n\r\n```php\r\n$injector->prepare('Zend\\Diactoros\\Response', function (&$response) {\r\n    $response = $response->withHeader('X-API-Version', 'v2.1');\r\n});\r\n```\r\n\r\nAttempting this will currently produce the following error:\r\n\r\n`Warning: Parameter 1 to {closure}() expected to be a reference, value given`\r\n\r\nBecause reflection is used to execute the closure, it is not possible to use references.\r\n\r\nWhat is the best way to handle immutable preparation?"},"comment":{"url":"https://api.github.com/repos/rdlowrey/auryn/issues/comments/134930578","html_url":"https://github.com/rdlowrey/auryn/issues/116#issuecomment-134930578","issue_url":"https://api.github.com/repos/rdlowrey/auryn/issues/116","id":134930578,"user":{"login":"J7mbo","id":2657310,"avatar_url":"https://avatars.githubusercontent.com/u/2657310?v=3","gravatar_id":"","url":"https://api.github.com/users/J7mbo","html_url":"https://github.com/J7mbo","followers_url":"https://api.github.com/users/J7mbo/followers","following_url":"https://api.github.com/users/J7mbo/following{/other_user}","gists_url":"https://api.github.com/users/J7mbo/gists{/gist_id}","starred_url":"https://api.github.com/users/J7mbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/J7mbo/subscriptions","organizations_url":"https://api.github.com/users/J7mbo/orgs","repos_url":"https://api.github.com/users/J7mbo/repos","events_url":"https://api.github.com/users/J7mbo/events{/privacy}","received_events_url":"https://api.github.com/users/J7mbo/received_events","type":"User","site_admin":false},"created_at":"2015-08-26T09:58:20Z","updated_at":"2015-08-26T09:58:20Z","body":"Hmm, looks like you're trying to tell the injector to, when it encounters an instance of `Zend\\Diactoros\\Response`, inject an altered version of it (with the header). Have you considered [instantation delegation](https://github.com/rdlowrey/auryn#instantiation-delegates) for this (basically, a factory).\r\n\r\nThis way your implementation doesn't know about the injector.\r\n\r\n    $apiResponseFactory = function() use ($response) {\r\n        return $response->withHeader('X-API-Version', 'v2.1');\r\n    };\r\n\r\n    $injector->delegate('Zend\\Diactoros\\Response', $apiResponseFactory);\r\n\r\nJust a suggestion. This might not work for you as it'll need to be in the same context as where you get the `$response` object.\r\n\r\nAn alternative would be to grab the injector in the `$apiResponseFactory` and use that to change the already shared `$response`. Or maybe that's complete rubbish! Perhaps @rdlowrey can chime in here :-) "}}