Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2 into cach…
Browse files Browse the repository at this point in the history
…e_plugin_priority

Conflicts:
	library/Zend/Cache/Storage/Adapter/AbstractAdapter.php
	library/Zend/Cache/Storage/Plugin/ClearByFactor.php
	library/Zend/Cache/Storage/Plugin/ExceptionHandler.php
	library/Zend/Cache/Storage/Plugin/IgnoreUserAbort.php
	library/Zend/Cache/Storage/Plugin/OptimizeByFactor.php
	library/Zend/Cache/Storage/Plugin/Serializer.php
  • Loading branch information
marc-mabe committed May 7, 2012
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 109 deletions.
73 changes: 34 additions & 39 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
Zend\Uri\Http,
Zend\Http\Header\Cookie,
Zend\Http\Header\SetCookie,
Zend\Http\Request as HttpRequest,
Zend\Http\Response as HttpResponse,
Zend\Http\Response\Stream as HttpResponseStream,
Zend\Stdlib\Parameters,
Zend\Stdlib\ParametersDescription,
Zend\Stdlib\Dispatchable,
Zend\Stdlib\RequestDescription,
Zend\Stdlib\ResponseDescription;
Zend\Stdlib\DispatchableInterface as Dispatchable,
Zend\Stdlib\RequestInterface as Request,
Zend\Stdlib\ResponseInterface as Response;

/**
* Http client
Expand Down Expand Up @@ -124,7 +126,7 @@ class Client implements Dispatchable
'useragent' => 'Zend\Http\Client',
'timeout' => 10,
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'httpversion' => Request::VERSION_11,
'httpversion' => HttpRequest::VERSION_11,
'storeresponse' => true,
'keepalive' => false,
'outputstream' => false,
Expand Down Expand Up @@ -195,7 +197,7 @@ public function setConfig($config = array())
*
* @param Client\Adapter|string $adapter
* @return Client
* @throws \Zend\Http\Client\Exception
* @throws Client\Exception\InvalidArgumentException
*/
public function setAdapter($adapter)
{
Expand Down Expand Up @@ -247,7 +249,7 @@ public function setRequest(Request $request)
public function getRequest()
{
if (empty($this->request)) {
$this->request = new Request();
$this->request = new HttpRequest();
}
return $this->request;
}
Expand All @@ -272,7 +274,7 @@ public function setResponse(Response $response)
public function getResponse()
{
if (empty($this->response)) {
$this->response = new Response();
$this->response = new HttpResponse();
}
return $this->response;
}
Expand Down Expand Up @@ -352,8 +354,8 @@ public function setMethod($method)
{
$method = $this->getRequest()->setMethod($method)->getMethod();

if (($method == Request::METHOD_POST || $method == Request::METHOD_PUT ||
$method == Request::METHOD_DELETE || $method == Request::METHOD_PATCH)
if (($method == HttpRequest::METHOD_POST || $method == HttpRequest::METHOD_PUT ||
$method == HttpRequest::METHOD_DELETE || $method == HttpRequest::METHOD_PATCH)
&& empty($this->encType)) {
$this->setEncType(self::ENC_URLENCODED);
}
Expand Down Expand Up @@ -465,14 +467,16 @@ protected function getCookieId($cookie)
*
* @param array|ArrayIterator|SetCookie|string $cookie
* @param string $value
* @param string $version
* @param string $maxAge
* @param string $domain
* @param string $expire
* @param string $path
* @param boolean $secure
* @param boolean $httponly
* @return Client
*/
public function addCookie($cookie, $value = null, $domain = null, $expire = null, $path = null, $secure = false, $httponly = true)
public function addCookie($cookie, $value = null, $version = null, $maxAge = null, $domain = null, $expire = null, $path = null, $secure = false, $httponly = true)
{
if (is_array($cookie) || $cookie instanceof ArrayIterator) {
foreach ($cookie as $setCookie) {
Expand All @@ -485,7 +489,7 @@ public function addCookie($cookie, $value = null, $domain = null, $expire = null
} elseif ($cookie instanceof SetCookie) {
$this->cookies[$this->getCookieId($cookie)] = $cookie;
} elseif (is_string($cookie) && $value !== null) {
$setCookie = new SetCookie($cookie, $value, $domain, $expire, $path, $secure, $httponly);
$setCookie = new SetCookie($cookie, $value, $version, $maxAge, $domain, $expire, $path, $secure, $httponly);
$this->cookies[$this->getCookieId($setCookie)] = $setCookie;
} else {
throw new Exception\InvalidArgumentException('Invalid parameter type passed as Cookie');
Expand Down Expand Up @@ -732,11 +736,11 @@ public function resetParameters($clearCookies = false)
/**
* Dispatch
*
* @param RequestDescription $request
* @param ResponseDescription $response
* @return ResponseDescription
* @param Request $request
* @param Response $response
* @return Response
*/
public function dispatch(RequestDescription $request, ResponseDescription $response = null)
public function dispatch(Request $request, Response $response = null)
{
$response = $this->send($request);
return $response;
Expand Down Expand Up @@ -832,20 +836,28 @@ public function send(Request $request = null)
}

if ($this->config['outputstream']) {
$stream = $this->getStream();
if (!is_resource($stream) && is_string($stream)) {
$stream = fopen($stream, 'r');
}
if (!is_resource($stream)) {
$stream = $this->getUri()->toString();
$stream = fopen($stream, 'r');
}
$streamMetaData = stream_get_meta_data($stream);
if ($streamMetaData['seekable']) {
rewind($stream);
}
// cleanup the adapter
$this->adapter->setOutputStream(null);
$response = Response\Stream::fromStream($response, $stream);
$response = HttpResponseStream::fromStream($response, $stream);
$response->setStreamName($this->streamName);
if (!is_string($this->config['outputstream'])) {
// we used temp name, will need to clean up
$response->setCleanup(true);
}
} else {
$response = Response::fromString($response);
$response = HttpResponse::fromString($response);
}

// Get the cookies from response (if any)
Expand All @@ -868,7 +880,7 @@ public function send(Request $request = null)
$response->getStatusCode() == 301))) {

$this->resetParameters();
$this->setMethod(Request::METHOD_GET);
$this->setMethod(HttpRequest::METHOD_GET);
}

// If we got a well formed absolute URI
Expand Down Expand Up @@ -1008,7 +1020,7 @@ protected function prepareHeaders($body, $uri)
$headers = array();

// Set the host header
if ($this->config['httpversion'] == Request::VERSION_11) {
if ($this->config['httpversion'] == HttpRequest::VERSION_11) {
$host = $uri->getHost();
// If the port is not default, add it
if (!(($uri->getScheme() == 'http' && $uri->getPort() == 80) ||
Expand Down Expand Up @@ -1067,7 +1079,7 @@ protected function prepareHeaders($body, $uri)
$fstat = fstat($body);
$headers['Content-Length'] = $fstat['size'];
} else {
$headers['Content-Length'] = static::strlen($body);
$headers['Content-Length'] = strlen($body);
}
}

Expand Down Expand Up @@ -1194,7 +1206,7 @@ protected function detectFileMimeType($file)
public function encodeFormData($boundary, $name, $value, $filename = null, $headers = array())
{
$ret = "--{$boundary}\r\n" .
'Content-Disposition: form-data; name="' . $name .'"';
'Content-Disposition: form-data; name="' . $name . '"';

if ($filename) {
$ret .= '; filename="' . $filename . '"';
Expand All @@ -1205,7 +1217,6 @@ public function encodeFormData($boundary, $name, $value, $filename = null, $head
$ret .= "{$hname}: {$hvalue}\r\n";
}
$ret .= "\r\n";

$ret .= "{$value}\r\n";

return $ret;
Expand Down Expand Up @@ -1288,20 +1299,4 @@ protected function doRequest(Http $uri, $method, $secure = false, $headers = arr

return $this->adapter->read();
}

/**
* Returns length of binary string in bytes
*
* @param string $str
* @return int the string length
*/
static public function strlen($str)
{
if (function_exists('mb_internal_encoding') &&
(((int)ini_get('mbstring.func_overload')) & 2)) {
return mb_strlen($str, '8bit');
} else {
return strlen($str);
}
}
}
4 changes: 3 additions & 1 deletion src/Client/Adapter/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ public function connect($host, $port = 80, $secure = false)

$flags = STREAM_CLIENT_CONNECT;
if ($this->config['persistent']) $flags |= STREAM_CLIENT_PERSISTENT;


$errno = null;
$errstr = '';
$this->socket = @stream_socket_client($host . ':' . $port,
$errno,
$errstr,
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace Zend\Http\Client;

use Zend\Stdlib\ParametersDescription,
use Zend\Stdlib\ParametersInterface,
Zend\Uri,
Zend\Http\Header\Cookie,
Zend\Http\Response;
Expand Down Expand Up @@ -48,7 +48,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Cookies //implements ParametersDescription
class Cookies //implements ParametersInterface
{
/**
* Return cookie(s) as a Zend\Http\Header\Cookie object
Expand Down
3 changes: 1 addition & 2 deletions src/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace Zend\Http;

use Zend\Stdlib\ParametersDescription,
Zend\Uri,
use Zend\Uri,
Zend\Http\Header\Cookie,
Zend\Http\Response;

Expand Down
Loading

0 comments on commit 4426545

Please sign in to comment.