Works as I originally expected in 2.0.3. I'm sure you're exactly right.

On Thu, Dec 6, 2012 at 11:12 AM, Marco Pivetta <[email protected]> wrote:
> Sorry, should have said "setter injection" :P
>
> I think `setStream` (
> https://github.com/zendframework/zf2/blob/master/library/Zend/Http/Client.php#L567-L577
> ) is called and the default parameter is used. Can you try this one with
> 2.0.3? I patched Zend\Di for 2.0.4~2.0.5 so that default parameters are used
> for injections. Before, it was probably injecting `null`.
>
> Marco Pivetta
>
> http://twitter.com/Ocramius
>
> http://ocramius.github.com/
>
>
>
> On 6 December 2012 11:51, gordon stratton <[email protected]> wrote:
>>
>> Indeed, that's what it seems like! I really didn't want to write
>> something like "A dependency injector is injecting dependencies. Why
>> is this?" though...
>>
>> Here is a (probably mailer-mangled) diff. As you can see, the major
>> difference is that outputstream is now true...
>>
>> $ diff -u without_injection with_injection
>> --- without_injection   2012-12-06 02:44:23.761785486 -0800
>> +++ with_injection      2012-12-06 02:44:55.978108015 -0800
>> @@ -1,12 +1,12 @@
>> -class Zend\Http\Client#4 (11) {
>> +class Zend\Http\Client#16 (11) {
>>    protected $response =>
>>    NULL
>>    protected $request =>
>> -  class Zend\Http\Request#5 (9) {
>> +  class Zend\Http\Request#17 (9) {
>>      protected $method =>
>>      string(3) "GET"
>>      protected $uri =>
>> -    class Zend\Uri\Http#6 (10) {
>> +    class Zend\Uri\Http#87 (10) {
>>        protected $validHostTypes =>
>>        int(11)
>>        protected $user =>
>> @@ -81,7 +81,7 @@
>>      'keepalive' =>
>>      bool(false)
>>      'outputstream' =>
>> -    bool(false)
>> +    bool(true)
>>      'encodecookies' =>
>>      bool(true)
>>      'rfc3986strict' =>
>>
>> On Thu, Dec 6, 2012 at 10:37 AM, Marco Pivetta <[email protected]> wrote:
>> > Looks like some injection is going on. Are you able to dump a diff of
>> > the
>> > two objects after instantiation?
>> >
>> > Marco Pivetta
>> >
>> > http://twitter.com/Ocramius
>> >
>> > http://ocramius.github.com/
>> >
>> >
>> >
>> > On 6 December 2012 11:26, gordon stratton <[email protected]>
>> > wrote:
>> >>
>> >> I ran into some behavior which I didn't expect when testing some code
>> >> that had Zend\Http\Client injected via Zend\Di. I narrowed down the
>> >> issue I was having to the illustration I will include inline.
>> >>
>> >> The issue is that Zend\Http\Client's response class when everything is
>> >> instantiated without Zend\Di is Zend\Http\Response, but with Zend\Di
>> >> it is Zend\Http\Response\Stream. When I then go to grab the body of
>> >> the response, decoding the body fails (it appears to be trying to
>> >> inflate an already-inflated body). In my inline snippet I have chosen
>> >> to fetch http://www.cnn.com to illustrate that behavior.
>> >>
>> >> I can work around this issue by configuring Zend\Di to prefer an
>> >> instantiated Zend\Http\Client, but I don't think I should need to do
>> >> that, and I would prefer to see that instantiated lazily like the rest
>> >> of my object graph.
>> >>
>> >> I hope you can see my intent here. Can anyone let me know where I've
>> >> gone wrong in my understanding?
>> >>
>> >> Versions of important things:
>> >>
>> >> PHP 5.4.4
>> >> Zend Framework 2.0.5
>> >>
>> >> <?php
>> >>
>> >> //
>> >> // your autoloader here
>> >> //
>> >>
>> >> $httpClient = new \Zend\Http\Client();
>> >> $httpClient->setUri('http://www.cnn.com');
>> >> $response = $httpClient->send();
>> >>
>> >> echo "Standard\n";
>> >> echo "--------\n\n";
>> >> echo "Response class: " . get_class($httpClient->getResponse()) . "\n";
>> >>
>> >> $httpClient->getResponse()->getBody();
>> >>
>> >> echo "\n\n";
>> >>
>> >> $di = new \Zend\Di\Di();
>> >>
>> >> $httpClient = $di->get('Zend\Http\Client');
>> >> $httpClient->setUri('http://www.cnn.com');
>> >> $response = $httpClient->send();
>> >>
>> >> echo "With DI\n";
>> >> echo "-------\n\n";
>> >> echo "Response class: " . get_class($httpClient->getResponse()) . "\n";
>> >>
>> >> $httpClient->getResponse()->getBody();
>> >>
>> >> --
>> >> List: [email protected]
>> >> Info: http://framework.zend.com/archives
>> >> Unsubscribe: [email protected]
>> >>
>> >>
>> >
>
>

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to