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: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to