Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http;
@@ -33,7 +31,7 @@ abstract class AbstractMessage extends Message
/**
* @var Headers|null
*/
protected $headers = null;
protected $headers;
/**
* Set the HTTP version for this object, one of 1.0 or 1.1

View File

@@ -1,16 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http;
use ArrayIterator;
use Traversable;
use Zend\Http\Client\Adapter\Curl;
use Zend\Http\Client\Adapter\Socket;
use Zend\Stdlib;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\ErrorHandler;
@@ -66,7 +66,12 @@ class Client implements Stdlib\DispatchableInterface
/**
* @var string
*/
protected $streamName = null;
protected $streamName;
/**
* @var resource|null
*/
protected $streamHandle = null;
/**
* @var array of Header\SetCookie
@@ -81,12 +86,12 @@ class Client implements Stdlib\DispatchableInterface
/**
* @var Request
*/
protected $lastRawRequest = null;
protected $lastRawRequest;
/**
* @var Response
*/
protected $lastRawResponse = null;
protected $lastRawResponse;
/**
* @var int
@@ -101,16 +106,19 @@ class Client implements Stdlib\DispatchableInterface
protected $config = [
'maxredirects' => 5,
'strictredirects' => false,
'useragent' => 'Zend\Http\Client',
'useragent' => Client::class,
'timeout' => 10,
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'connecttimeout' => null,
'adapter' => Socket::class,
'httpversion' => Request::VERSION_11,
'storeresponse' => true,
'keepalive' => false,
'outputstream' => false,
'encodecookies' => true,
'argseparator' => null,
'rfc3986strict' => false
'rfc3986strict' => false,
'sslcafile' => null,
'sslcapath' => null,
];
/**
@@ -121,7 +129,7 @@ class Client implements Stdlib\DispatchableInterface
*
* @var resource
*/
protected static $fileInfoDb = null;
protected static $fileInfoDb;
/**
* Constructor
@@ -151,7 +159,7 @@ class Client implements Stdlib\DispatchableInterface
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (!is_array($options)) {
if (! is_array($options)) {
throw new Client\Exception\InvalidArgumentException('Config parameter is not valid');
}
@@ -181,8 +189,10 @@ class Client implements Stdlib\DispatchableInterface
public function setAdapter($adapter)
{
if (is_string($adapter)) {
if (!class_exists($adapter)) {
throw new Client\Exception\InvalidArgumentException('Unable to locate adapter class "' . $adapter . '"');
if (! class_exists($adapter)) {
throw new Client\Exception\InvalidArgumentException(
'Unable to locate adapter class "' . $adapter . '"'
);
}
$adapter = new $adapter;
}
@@ -301,7 +311,7 @@ class Client implements Stdlib\DispatchableInterface
*/
public function setUri($uri)
{
if (!empty($uri)) {
if (! empty($uri)) {
// remember host of last request
$lastHost = $this->getRequest()->getUri()->getHost();
$this->getRequest()->setUri($uri);
@@ -310,7 +320,7 @@ class Client implements Stdlib\DispatchableInterface
// reasons, see #4215 for a discussion - currently authentication is also
// cleared for peer subdomains due to technical limits
$nextHost = $this->getRequest()->getUri()->getHost();
if (!preg_match('/' . preg_quote($lastHost, '/') . '$/i', $nextHost)) {
if (! preg_match('/' . preg_quote($lastHost, '/') . '$/i', $nextHost)) {
$this->clearAuth();
}
@@ -384,7 +394,7 @@ class Client implements Stdlib\DispatchableInterface
*/
public function setArgSeparator($argSeparator)
{
$this->setOptions(["argseparator" => $argSeparator]);
$this->setOptions(['argseparator' => $argSeparator]);
return $this;
}
@@ -546,8 +556,17 @@ class Client implements Stdlib\DispatchableInterface
* @throws Exception\InvalidArgumentException
* @return Client
*/
public function addCookie($cookie, $value = null, $expire = null, $path = null, $domain = null, $secure = false, $httponly = true, $maxAge = null, $version = null)
{
public function addCookie(
$cookie,
$value = null,
$expire = null,
$path = null,
$domain = null,
$secure = false,
$httponly = true,
$maxAge = null,
$version = null
) {
if (is_array($cookie) || $cookie instanceof ArrayIterator) {
foreach ($cookie as $setCookie) {
if ($setCookie instanceof Header\SetCookie) {
@@ -557,7 +576,17 @@ class Client implements Stdlib\DispatchableInterface
}
}
} elseif (is_string($cookie) && $value !== null) {
$setCookie = new Header\SetCookie($cookie, $value, $expire, $path, $domain, $secure, $httponly, $maxAge, $version);
$setCookie = new Header\SetCookie(
$cookie,
$value,
$expire,
$path,
$domain,
$secure,
$httponly,
$maxAge,
$version
);
$this->cookies[$this->getCookieId($setCookie)] = $setCookie;
} elseif ($cookie instanceof Header\SetCookie) {
$this->cookies[$this->getCookieId($cookie)] = $cookie;
@@ -659,7 +688,7 @@ class Client implements Stdlib\DispatchableInterface
*/
public function setStream($streamfile = true)
{
$this->setOptions(["outputstream" => $streamfile]);
$this->setOptions(['outputstream' => $streamfile]);
return $this;
}
@@ -686,22 +715,22 @@ class Client implements Stdlib\DispatchableInterface
{
$this->streamName = $this->config['outputstream'];
if (!is_string($this->streamName)) {
if (! is_string($this->streamName)) {
// If name is not given, create temp name
$this->streamName = tempnam(
isset($this->config['streamtmpdir']) ? $this->config['streamtmpdir'] : sys_get_temp_dir(),
'Zend\Http\Client'
Client::class
);
}
ErrorHandler::start();
$fp = fopen($this->streamName, "w+b");
$fp = fopen($this->streamName, 'w+b');
$error = ErrorHandler::stop();
if (false === $fp) {
if ($this->adapter instanceof Client\Adapter\AdapterInterface) {
$this->adapter->close();
}
throw new Exception\RuntimeException("Could not open temp file {$this->streamName}", 0, $error);
throw new Exception\RuntimeException(sprintf('Could not open temp file %s', $this->streamName), 0, $error);
}
return $fp;
@@ -719,18 +748,21 @@ class Client implements Stdlib\DispatchableInterface
*/
public function setAuth($user, $password, $type = self::AUTH_BASIC)
{
if (!defined('static::AUTH_' . strtoupper($type))) {
throw new Exception\InvalidArgumentException("Invalid or not supported authentication type: '$type'");
if (! defined('static::AUTH_' . strtoupper($type))) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid or not supported authentication type: \'%s\'',
$type
));
}
if (empty($user)) {
throw new Exception\InvalidArgumentException("The username cannot be empty");
throw new Exception\InvalidArgumentException('The username cannot be empty');
}
$this->auth = [
'user' => $user,
'password' => $password,
'type' => $type
'type' => $type,
];
return $this;
@@ -758,25 +790,33 @@ class Client implements Stdlib\DispatchableInterface
*/
protected function calcAuthDigest($user, $password, $type = self::AUTH_BASIC, $digest = [], $entityBody = null)
{
if (!defined('self::AUTH_' . strtoupper($type))) {
throw new Exception\InvalidArgumentException("Invalid or not supported authentication type: '$type'");
if (! defined('self::AUTH_' . strtoupper($type))) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid or not supported authentication type: \'%s\'',
$type
));
}
$response = false;
switch (strtolower($type)) {
case self::AUTH_BASIC :
case self::AUTH_BASIC:
// In basic authentication, the user name cannot contain ":"
if (strpos($user, ':') !== false) {
throw new Exception\InvalidArgumentException("The user name cannot contain ':' in Basic HTTP authentication");
throw new Exception\InvalidArgumentException(
'The user name cannot contain \':\' in Basic HTTP authentication'
);
}
$response = base64_encode($user . ':' . $password);
break;
case self::AUTH_DIGEST :
case self::AUTH_DIGEST:
if (empty($digest)) {
throw new Exception\InvalidArgumentException("The digest cannot be empty");
throw new Exception\InvalidArgumentException('The digest cannot be empty');
}
foreach ($digest as $key => $value) {
if (!defined('self::DIGEST_' . strtoupper($key))) {
throw new Exception\InvalidArgumentException("Invalid or not supported digest authentication parameter: '$key'");
if (! defined('self::DIGEST_' . strtoupper($key))) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid or not supported digest authentication parameter: \'%s\'',
$key
));
}
}
$ha1 = md5($user . ':' . $digest['realm'] . ':' . $password);
@@ -784,7 +824,9 @@ class Client implements Stdlib\DispatchableInterface
$ha2 = md5($this->getMethod() . ':' . $this->getUri()->getPath());
} elseif (strtolower($digest['qop']) == 'auth-int') {
if (empty($entityBody)) {
throw new Exception\InvalidArgumentException("I cannot use the auth-int digest authentication without the entity body");
throw new Exception\InvalidArgumentException(
'I cannot use the auth-int digest authentication without the entity body'
);
}
$ha2 = md5($this->getMethod() . ':' . $this->getUri()->getPath() . ':' . md5($entityBody));
}
@@ -838,10 +880,10 @@ class Client implements Stdlib\DispatchableInterface
// query
$query = $this->getRequest()->getQuery();
if (!empty($query)) {
if (! empty($query)) {
$queryArray = $query->toArray();
if (!empty($queryArray)) {
if (! empty($queryArray)) {
$newUri = $uri->toString();
$queryString = http_build_query($queryArray, null, $this->getArgSeparator());
@@ -859,7 +901,7 @@ class Client implements Stdlib\DispatchableInterface
}
}
// If we have no ports, set the defaults
if (!$uri->getPort()) {
if (! $uri->getPort()) {
$uri->setPort($uri->getScheme() == 'https' ? 443 : 80);
}
@@ -884,15 +926,21 @@ class Client implements Stdlib\DispatchableInterface
}
// check that adapter supports streaming before using it
if (is_resource($body) && !($adapter instanceof Client\Adapter\StreamInterface)) {
if (is_resource($body) && ! ($adapter instanceof Client\Adapter\StreamInterface)) {
throw new Client\Exception\RuntimeException('Adapter does not support streaming');
}
$this->streamHandle = null;
// calling protected method to allow extending classes
// to wrap the interaction with the adapter
$response = $this->doRequest($uri, $method, $secure, $headers, $body);
$stream = $this->streamHandle;
$this->streamHandle = null;
if (! $response) {
if ($stream !== null) {
fclose($stream);
}
throw new Exception\RuntimeException('Unable to read response, or response is empty');
}
@@ -903,9 +951,11 @@ class Client implements Stdlib\DispatchableInterface
}
if ($this->config['outputstream']) {
$stream = $this->getStream();
if (!is_resource($stream) && is_string($stream)) {
$stream = fopen($stream, 'r');
if ($stream === null) {
$stream = $this->getStream();
if (! is_resource($stream) && is_string($stream)) {
$stream = fopen($stream, 'r');
}
}
$streamMetaData = stream_get_meta_data($stream);
if ($streamMetaData['seekable']) {
@@ -915,7 +965,7 @@ class Client implements Stdlib\DispatchableInterface
$adapter->setOutputStream(null);
$response = Response\Stream::fromStream($response, $stream);
$response->setStreamName($this->streamName);
if (!is_string($this->config['outputstream'])) {
if (! is_string($this->config['outputstream'])) {
// we used temp name, will need to clean up
$response->setCleanup(true);
}
@@ -925,7 +975,7 @@ class Client implements Stdlib\DispatchableInterface
// Get the cookies from response (if any)
$setCookies = $response->getCookie();
if (!empty($setCookies)) {
if (! empty($setCookies)) {
$this->addCookie($setCookies);
}
@@ -937,16 +987,18 @@ class Client implements Stdlib\DispatchableInterface
// Check whether we send the exact same request again, or drop the parameters
// and send a GET request
if ($response->getStatusCode() == 303 ||
((! $this->config['strictredirects']) && ($response->getStatusCode() == 302 ||
$response->getStatusCode() == 301))) {
if ($response->getStatusCode() == 303
|| ((! $this->config['strictredirects'])
&& ($response->getStatusCode() == 302 || $response->getStatusCode() == 301))
) {
$this->resetParameters(false, false);
$this->setMethod(Request::METHOD_GET);
}
// If we got a well formed absolute URI
if (($scheme = substr($location, 0, 6)) &&
($scheme == 'http:/' || $scheme == 'https:')) {
if (($scheme = substr($location, 0, 6))
&& ($scheme == 'http:/' || $scheme == 'https:')
) {
// setURI() clears parameters if host changed, see #4215
$this->setUri($location);
} else {
@@ -965,7 +1017,7 @@ class Client implements Stdlib\DispatchableInterface
} else {
// Get the current path directory, removing any trailing slashes
$path = $this->getUri()->getPath();
$path = rtrim(substr($path, 0, strrpos($path, '/')), "/");
$path = rtrim(substr($path, 0, strrpos($path, '/')), '/');
$this->getUri()->setPath($path . '/' . $location);
}
}
@@ -1021,9 +1073,12 @@ class Client implements Stdlib\DispatchableInterface
$data = file_get_contents($filename);
$error = ErrorHandler::stop();
if ($data === false) {
throw new Exception\RuntimeException("Unable to read file '{$filename}' for upload", 0, $error);
throw new Exception\RuntimeException(sprintf(
'Unable to read file \'%s\' for upload',
$filename
), 0, $error);
}
if (!$ctype) {
if (! $ctype) {
$ctype = $this->detectFileMimeType($filename);
}
}
@@ -1032,7 +1087,7 @@ class Client implements Stdlib\DispatchableInterface
'formname' => $formname,
'filename' => basename($filename),
'ctype' => $ctype,
'data' => $data
'data' => $data,
]);
return $this;
@@ -1047,7 +1102,7 @@ class Client implements Stdlib\DispatchableInterface
public function removeFileUpload($filename)
{
$file = $this->getRequest()->getFiles()->get($filename);
if (!empty($file)) {
if (! empty($file)) {
$this->getRequest()->getFiles()->set($filename, null);
return true;
}
@@ -1066,7 +1121,7 @@ class Client implements Stdlib\DispatchableInterface
{
$validCookies = [];
if (!empty($this->cookies)) {
if (! empty($this->cookies)) {
foreach ($this->cookies as $id => $cookie) {
if ($cookie->isExpired()) {
unset($this->cookies[$id]);
@@ -1102,8 +1157,9 @@ class Client implements Stdlib\DispatchableInterface
if ($this->config['httpversion'] == Request::VERSION_11) {
$host = $uri->getHost();
// If the port is not default, add it
if (!(($uri->getScheme() == 'http' && $uri->getPort() == 80) ||
($uri->getScheme() == 'https' && $uri->getPort() == 443))) {
if (! (($uri->getScheme() == 'http' && $uri->getPort() == 80)
|| ($uri->getScheme() == 'https' && $uri->getPort() == 443))
) {
$host .= ':' . $uri->getPort();
}
@@ -1111,15 +1167,15 @@ class Client implements Stdlib\DispatchableInterface
}
// Set the connection header
if (!$this->getRequest()->getHeaders()->has('Connection')) {
if (!$this->config['keepalive']) {
if (! $this->getRequest()->getHeaders()->has('Connection')) {
if (! $this->config['keepalive']) {
$headers['Connection'] = 'close';
}
}
// Set the Accept-encoding header if not set - depending on whether
// zlib is available or not.
if (!$this->getRequest()->getHeaders()->has('Accept-Encoding')) {
if (! $this->getRequest()->getHeaders()->has('Accept-Encoding')) {
if (function_exists('gzinflate')) {
$headers['Accept-Encoding'] = 'gzip, deflate';
} else {
@@ -1127,24 +1183,26 @@ class Client implements Stdlib\DispatchableInterface
}
}
// Set the user agent header
if (!$this->getRequest()->getHeaders()->has('User-Agent') && isset($this->config['useragent'])) {
if (! $this->getRequest()->getHeaders()->has('User-Agent') && isset($this->config['useragent'])) {
$headers['User-Agent'] = $this->config['useragent'];
}
// Set HTTP authentication if needed
if (!empty($this->auth)) {
if (! empty($this->auth)) {
switch ($this->auth['type']) {
case self::AUTH_BASIC :
case self::AUTH_BASIC:
$auth = $this->calcAuthDigest($this->auth['user'], $this->auth['password'], $this->auth['type']);
if ($auth !== false) {
$headers['Authorization'] = 'Basic ' . $auth;
}
break;
case self::AUTH_DIGEST :
if (!$this->adapter instanceof Client\Adapter\Curl) {
throw new Exception\RuntimeException("The digest authentication is only available for curl adapters (Zend\\Http\\Client\\Adapter\\Curl)");
case self::AUTH_DIGEST:
if (! $this->adapter instanceof Client\Adapter\Curl) {
throw new Exception\RuntimeException(sprintf(
'The digest authentication is only available for curl adapters (%s)',
Curl::class
));
}
$this->adapter->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
@@ -1154,11 +1212,11 @@ class Client implements Stdlib\DispatchableInterface
// Content-type
$encType = $this->getEncType();
if (!empty($encType)) {
if (! empty($encType)) {
$headers['Content-Type'] = $encType;
}
if (!empty($body)) {
if (! empty($body)) {
if (is_resource($body)) {
$fstat = fstat($body);
$headers['Content-Length'] = $fstat['size'];
@@ -1176,7 +1234,6 @@ class Client implements Stdlib\DispatchableInterface
return $headers;
}
/**
* Prepare the request body (for PATCH, POST and PUT requests)
*
@@ -1191,17 +1248,17 @@ class Client implements Stdlib\DispatchableInterface
}
$rawBody = $this->getRequest()->getContent();
if (!empty($rawBody)) {
if (! empty($rawBody)) {
return $rawBody;
}
$body = '';
$totalFiles = 0;
$hasFiles = false;
if (!$this->getRequest()->getHeaders()->has('Content-Type')) {
$totalFiles = count($this->getRequest()->getFiles()->toArray());
if (! $this->getRequest()->getHeaders()->has('Content-Type')) {
$hasFiles = ! empty($this->getRequest()->getFiles()->toArray());
// If we have files to upload, force encType to multipart/form-data
if ($totalFiles > 0) {
if ($hasFiles) {
$this->setEncType(self::ENC_FORMDATA);
}
} else {
@@ -1209,7 +1266,7 @@ class Client implements Stdlib\DispatchableInterface
}
// If we have POST parameters or files, encode and add them to the body
if (count($this->getRequest()->getPost()->toArray()) > 0 || $totalFiles > 0) {
if (! empty($this->getRequest()->getPost()->toArray()) || $hasFiles) {
if (stripos($this->getEncType(), self::ENC_FORMDATA) === 0) {
$boundary = '---ZENDHTTPCLIENT-' . md5(microtime());
$this->setEncType(self::ENC_FORMDATA, $boundary);
@@ -1223,14 +1280,23 @@ class Client implements Stdlib\DispatchableInterface
// Encode files
foreach ($this->getRequest()->getFiles()->toArray() as $file) {
$fhead = ['Content-Type' => $file['ctype']];
$body .= $this->encodeFormData($boundary, $file['formname'], $file['data'], $file['filename'], $fhead);
$body .= $this->encodeFormData(
$boundary,
$file['formname'],
$file['data'],
$file['filename'],
$fhead
);
}
$body .= "--{$boundary}--\r\n";
$body .= '--' . $boundary . '--' . "\r\n";
} elseif (stripos($this->getEncType(), self::ENC_URLENCODED) === 0) {
// Encode body as application/x-www-form-urlencoded
$body = http_build_query($this->getRequest()->getPost()->toArray());
$body = http_build_query($this->getRequest()->getPost()->toArray(), null, '&');
} else {
throw new Client\Exception\RuntimeException("Cannot handle content type '{$this->encType}' automatically");
throw new Client\Exception\RuntimeException(sprintf(
'Cannot handle content type \'%s\' automatically',
$this->encType
));
}
}
@@ -1291,8 +1357,8 @@ class Client implements Stdlib\DispatchableInterface
*/
public function encodeFormData($boundary, $name, $value, $filename = null, $headers = [])
{
$ret = "--{$boundary}\r\n" .
'Content-Disposition: form-data; name="' . $name . '"';
$ret = '--' . $boundary . "\r\n"
. 'Content-Disposition: form-data; name="' . $name . '"';
if ($filename) {
$ret .= '; filename="' . $filename . '"';
@@ -1300,10 +1366,10 @@ class Client implements Stdlib\DispatchableInterface
$ret .= "\r\n";
foreach ($headers as $hname => $hvalue) {
$ret .= "{$hname}: {$hvalue}\r\n";
$ret .= $hname . ': ' . $hvalue . "\r\n";
}
$ret .= "\r\n";
$ret .= "{$value}\r\n";
$ret .= $value . "\r\n";
return $ret;
}
@@ -1324,7 +1390,7 @@ class Client implements Stdlib\DispatchableInterface
*/
protected function flattenParametersArray($parray, $prefix = null)
{
if (!is_array($parray)) {
if (! is_array($parray)) {
return $parray;
}
@@ -1336,7 +1402,7 @@ class Client implements Stdlib\DispatchableInterface
if (is_int($name)) {
$key = $prefix . '[]';
} else {
$key = $prefix . "[$name]";
$key = $prefix . sprintf('[%s]', $name);
}
} else {
$key = $name;
@@ -1371,8 +1437,8 @@ class Client implements Stdlib\DispatchableInterface
if ($this->config['outputstream']) {
if ($this->adapter instanceof Client\Adapter\StreamInterface) {
$stream = $this->openTempStream();
$this->adapter->setOutputStream($stream);
$this->streamHandle = $this->openTempStream();
$this->adapter->setOutputStream($this->streamHandle);
} else {
throw new Exception\RuntimeException('Adapter does not support streaming');
}
@@ -1406,20 +1472,24 @@ class Client implements Stdlib\DispatchableInterface
case self::AUTH_BASIC:
// In basic authentication, the user name cannot contain ":"
if (strpos($user, ':') !== false) {
throw new Client\Exception\InvalidArgumentException("The user name cannot contain ':' in 'Basic' HTTP authentication");
throw new Client\Exception\InvalidArgumentException(
'The user name cannot contain \':\' in \'Basic\' HTTP authentication'
);
}
return 'Basic ' . base64_encode($user . ':' . $password);
//case self::AUTH_DIGEST:
/**
* @todo Implement digest authentication
*/
* @todo Implement digest authentication
*/
// break;
default:
throw new Client\Exception\InvalidArgumentException("Not a supported HTTP authentication type: '$type'");
throw new Client\Exception\InvalidArgumentException(sprintf(
'Not a supported HTTP authentication type: \'%s\'',
$type
));
}
return;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter;
@@ -20,6 +18,13 @@ use Zend\Stdlib\ArrayUtils;
*/
class Curl implements HttpAdapter, StreamInterface
{
/**
* Operation timeout.
*
* @var int
*/
const ERROR_OPERATION_TIMEDOUT = 28;
/**
* Parameters array
*
@@ -39,7 +44,7 @@ class Curl implements HttpAdapter, StreamInterface
*
* @var resource|null
*/
protected $curl = null;
protected $curl;
/**
* List of cURL options that should never be overwritten
@@ -53,7 +58,7 @@ class Curl implements HttpAdapter, StreamInterface
*
* @var string
*/
protected $response = null;
protected $response;
/**
* Stream for storing output
@@ -71,7 +76,7 @@ class Curl implements HttpAdapter, StreamInterface
*/
public function __construct()
{
if (!extension_loaded('curl')) {
if (! extension_loaded('curl')) {
throw new AdapterException\InitializationException(
'cURL extension has to be loaded to use this Zend\Http\Client adapter'
);
@@ -104,10 +109,11 @@ class Curl implements HttpAdapter, StreamInterface
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (!is_array($options)) {
throw new AdapterException\InvalidArgumentException(
'Array or Traversable object expected, got ' . gettype($options)
);
if (! is_array($options)) {
throw new AdapterException\InvalidArgumentException(sprintf(
'Array or Traversable object expected, got %s',
gettype($options)
));
}
/** Config Key Normalization */
@@ -117,7 +123,7 @@ class Curl implements HttpAdapter, StreamInterface
}
if (isset($options['proxyuser']) && isset($options['proxypass'])) {
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $options['proxyuser'] . ":" . $options['proxypass']);
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $options['proxyuser'] . ':' . $options['proxypass']);
unset($options['proxyuser'], $options['proxypass']);
}
@@ -166,7 +172,7 @@ class Curl implements HttpAdapter, StreamInterface
*/
public function setCurlOption($option, $value)
{
if (!isset($this->config['curloptions'])) {
if (! isset($this->config['curloptions'])) {
$this->config['curloptions'] = [];
}
$this->config['curloptions'][$option] = $value;
@@ -195,13 +201,22 @@ class Curl implements HttpAdapter, StreamInterface
curl_setopt($this->curl, CURLOPT_PORT, intval($port));
}
if (isset($this->config['timeout'])) {
if (isset($this->config['connecttimeout'])) {
$connectTimeout = $this->config['connecttimeout'];
} elseif (isset($this->config['timeout'])) {
$connectTimeout = $this->config['timeout'];
} else {
$connectTimeout = null;
}
if ($connectTimeout !== null) {
if (defined('CURLOPT_CONNECTTIMEOUT_MS')) {
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT_MS, $this->config['timeout'] * 1000);
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT_MS, $connectTimeout * 1000);
} else {
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $this->config['timeout']);
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $connectTimeout);
}
}
if (isset($this->config['timeout'])) {
if (defined('CURLOPT_TIMEOUT_MS')) {
curl_setopt($this->curl, CURLOPT_TIMEOUT_MS, $this->config['timeout'] * 1000);
} else {
@@ -209,12 +224,19 @@ class Curl implements HttpAdapter, StreamInterface
}
}
if (isset($this->config['sslcafile']) && $this->config['sslcafile']) {
curl_setopt($this->curl, CURLOPT_CAINFO, $this->config['sslcafile']);
}
if (isset($this->config['sslcapath']) && $this->config['sslcapath']) {
curl_setopt($this->curl, CURLOPT_CAPATH, $this->config['sslcapath']);
}
if (isset($this->config['maxredirects'])) {
// Set Max redirects
curl_setopt($this->curl, CURLOPT_MAXREDIRS, $this->config['maxredirects']);
}
if (!$this->curl) {
if (! $this->curl) {
$this->close();
throw new AdapterException\RuntimeException('Unable to Connect to ' . $host . ':' . $port);
@@ -247,16 +269,17 @@ class Curl implements HttpAdapter, StreamInterface
* to wrong host, no PUT file defined, unsupported method, or unsupported
* cURL option.
* @throws AdapterException\InvalidArgumentException if $method is currently not supported
* @throws AdapterException\TimeoutException if connection timed out
*/
public function write($method, $uri, $httpVersion = 1.1, $headers = [], $body = '')
{
// Make sure we're properly connected
if (!$this->curl) {
throw new AdapterException\RuntimeException("Trying to write but we are not connected");
if (! $this->curl) {
throw new AdapterException\RuntimeException('Trying to write but we are not connected');
}
if ($this->connectedTo[0] != $uri->getHost() || $this->connectedTo[1] != $uri->getPort()) {
throw new AdapterException\RuntimeException("Trying to write but we are connected to the wrong host");
throw new AdapterException\RuntimeException('Trying to write but we are connected to the wrong host');
}
// set URL
@@ -282,8 +305,8 @@ class Curl implements HttpAdapter, StreamInterface
if (isset($this->config['curloptions'][CURLOPT_INFILE])) {
// Now we will probably already have Content-Length set, so that we have to delete it
// from $headers at this point:
if (!isset($headers['Content-Length'])
&& !isset($this->config['curloptions'][CURLOPT_INFILESIZE])
if (! isset($headers['Content-Length'])
&& ! isset($this->config['curloptions'][CURLOPT_INFILESIZE])
) {
throw new AdapterException\RuntimeException(
'Cannot set a file-handle for cURL option CURLOPT_INFILE'
@@ -303,46 +326,49 @@ class Curl implements HttpAdapter, StreamInterface
$curlMethod = CURLOPT_UPLOAD;
} else {
$curlMethod = CURLOPT_CUSTOMREQUEST;
$curlValue = "PUT";
$curlValue = 'PUT';
}
break;
case 'PATCH':
$curlMethod = CURLOPT_CUSTOMREQUEST;
$curlValue = "PATCH";
$curlValue = 'PATCH';
break;
case 'DELETE':
$curlMethod = CURLOPT_CUSTOMREQUEST;
$curlValue = "DELETE";
$curlValue = 'DELETE';
break;
case 'OPTIONS':
$curlMethod = CURLOPT_CUSTOMREQUEST;
$curlValue = "OPTIONS";
$curlValue = 'OPTIONS';
break;
case 'TRACE':
$curlMethod = CURLOPT_CUSTOMREQUEST;
$curlValue = "TRACE";
$curlValue = 'TRACE';
break;
case 'HEAD':
$curlMethod = CURLOPT_CUSTOMREQUEST;
$curlValue = "HEAD";
$curlValue = 'HEAD';
break;
default:
// For now, through an exception for unsupported request methods
throw new AdapterException\InvalidArgumentException("Method '$method' currently not supported");
throw new AdapterException\InvalidArgumentException(sprintf(
'Method \'%s\' currently not supported',
$method
));
}
if (is_resource($body) && $curlMethod != CURLOPT_UPLOAD) {
throw new AdapterException\RuntimeException("Streaming requests are allowed only with PUT");
throw new AdapterException\RuntimeException('Streaming requests are allowed only with PUT');
}
// get http version to use
$curlHttp = ($httpVersion == 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
$curlHttp = $httpVersion == 1.1 ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
// mark as HTTP request and set HTTP method
curl_setopt($this->curl, CURLOPT_HTTP_VERSION, $curlHttp);
@@ -354,7 +380,7 @@ class Curl implements HttpAdapter, StreamInterface
if ($this->outputStream) {
// headers will be read into the response
curl_setopt($this->curl, CURLOPT_HEADER, false);
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, [$this, "readHeader"]);
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, [$this, 'readHeader']);
// and data will be written into the file
curl_setopt($this->curl, CURLOPT_FILE, $this->outputStream);
} else {
@@ -373,7 +399,7 @@ class Curl implements HttpAdapter, StreamInterface
}
// set additional headers
if (!isset($headers['Accept'])) {
if (! isset($headers['Accept'])) {
$headers['Accept'] = '';
}
$curlHeaders = [];
@@ -402,7 +428,7 @@ class Curl implements HttpAdapter, StreamInterface
// set additional curl options
if (isset($this->config['curloptions'])) {
foreach ((array) $this->config['curloptions'] as $k => $v) {
if (!in_array($k, $this->invalidOverwritableCurlOptions)) {
if (! in_array($k, $this->invalidOverwritableCurlOptions)) {
if (curl_setopt($this->curl, $k, $v) == false) {
throw new AdapterException\RuntimeException(sprintf(
'Unknown or erroreous cURL option "%s" set',
@@ -413,19 +439,30 @@ class Curl implements HttpAdapter, StreamInterface
}
}
$this->response = '';
// send the request
$response = curl_exec($this->curl);
// if we used streaming, headers are already there
if (!is_resource($this->outputStream)) {
if (! is_resource($this->outputStream)) {
$this->response = $response;
}
$request = curl_getinfo($this->curl, CURLINFO_HEADER_OUT);
$request .= $body;
if (empty($this->response)) {
throw new AdapterException\RuntimeException("Error in cURL request: " . curl_error($this->curl));
if ($response === false || empty($this->response)) {
if (curl_errno($this->curl) === static::ERROR_OPERATION_TIMEDOUT) {
throw new AdapterException\TimeoutException(
'Read timed out',
AdapterException\TimeoutException::READ_TIMEOUT
);
}
throw new AdapterException\RuntimeException(sprintf(
'Error in cURL request: %s',
curl_error($this->curl)
));
}
// separating header from body because it is dangerous to accidentially replace strings in the body
@@ -434,7 +471,7 @@ class Curl implements HttpAdapter, StreamInterface
// cURL automatically decodes chunked-messages, this means we have to
// disallow the Zend\Http\Response to do it again.
$responseHeaders = preg_replace("/Transfer-Encoding:\s*chunked\\r\\n/i", "", $responseHeaders);
$responseHeaders = preg_replace("/Transfer-Encoding:\s*chunked\\r\\n/i", '', $responseHeaders);
// cURL can automatically handle content encoding; prevent double-decoding from occurring
if (isset($this->config['curloptions'][CURLOPT_ENCODING])

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter\Exception;

View File

@@ -1,16 +1,12 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter\Exception;
/**
*/
class InitializationException extends RuntimeException
{
}

View File

@@ -1,18 +1,14 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter\Exception;
use Zend\Http\Client\Exception;
/**
*/
class InvalidArgumentException extends Exception\InvalidArgumentException implements
ExceptionInterface
{

View File

@@ -1,18 +1,14 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter\Exception;
use Zend\Http\Client\Exception;
/**
*/
class OutOfRangeException extends Exception\OutOfRangeException implements
ExceptionInterface
{

View File

@@ -1,18 +1,14 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter\Exception;
use Zend\Http\Client\Exception;
/**
*/
class RuntimeException extends Exception\RuntimeException implements
ExceptionInterface
{

View File

@@ -1,16 +1,12 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter\Exception;
/**
*/
class TimeoutException extends RuntimeException implements ExceptionInterface
{
const READ_TIMEOUT = 1000;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter;
@@ -31,19 +29,21 @@ class Proxy extends Socket
* @var array
*/
protected $config = [
'persistent' => false,
'ssltransport' => 'ssl',
'sslcert' => null,
'sslpassphrase' => null,
'sslverifypeer' => true,
'sslcafile' => null,
'sslcapath' => null,
'sslallowselfsigned' => false,
'sslusecontext' => false,
'sslverifypeername' => true,
'proxy_host' => '',
'proxy_port' => 8080,
'proxy_user' => '',
'proxy_pass' => '',
'proxy_auth' => Client::AUTH_BASIC,
'persistent' => false
];
/**
@@ -62,7 +62,7 @@ class Proxy extends Socket
{
//enforcing that the proxy keys are set in the form proxy_*
foreach ($options as $k => $v) {
if (preg_match("/^proxy[a-z]+/", $k)) {
if (preg_match('/^proxy[a-z]+/', $k)) {
$options['proxy_' . substr($k, 5, strlen($k))] = $v;
unset($options[$k]);
}
@@ -123,25 +123,29 @@ class Proxy extends Socket
// Make sure we're properly connected
if (! $this->socket) {
throw new AdapterException\RuntimeException("Trying to write but we are not connected");
throw new AdapterException\RuntimeException('Trying to write but we are not connected');
}
$host = $this->config['proxy_host'];
$port = $this->config['proxy_port'];
if ($this->connectedTo[0] != "tcp://$host" || $this->connectedTo[1] != $port) {
throw new AdapterException\RuntimeException("Trying to write but we are connected to the wrong proxy server");
if ($this->connectedTo[0] != sprintf('tcp://%s', $host) || $this->connectedTo[1] != $port) {
throw new AdapterException\RuntimeException(
'Trying to write but we are connected to the wrong proxy server'
);
}
// Add Proxy-Authorization header
if ($this->config['proxy_user'] && ! isset($headers['proxy-authorization'])) {
$headers['proxy-authorization'] = Client::encodeAuthHeader(
$this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']
$this->config['proxy_user'],
$this->config['proxy_pass'],
$this->config['proxy_auth']
);
}
// if we are proxying HTTPS, preform CONNECT handshake with the proxy
if ($uri->getScheme() == 'https' && (! $this->negotiated)) {
if ($uri->getScheme() == 'https' && ! $this->negotiated) {
$this->connectHandshake($uri->getHost(), $uri->getPort(), $httpVer, $headers);
$this->negotiated = true;
}
@@ -155,17 +159,17 @@ class Proxy extends Socket
if ($uri->getQuery()) {
$path .= '?' . $uri->getQuery();
}
$request = "$method $path HTTP/$httpVer\r\n";
$request = sprintf('%s %s HTTP/%s%s', $method, $path, $httpVer, "\r\n");
} else {
$request = "$method $uri HTTP/$httpVer\r\n";
$request = sprintf('%s %s HTTP/%s%s', $method, $uri, $httpVer, "\r\n");
}
// Add all headers to the request string
foreach ($headers as $k => $v) {
if (is_string($k)) {
$v = "$k: $v";
$v = $k . ': ' . $v;
}
$request .= "$v\r\n";
$request .= $v . "\r\n";
}
if (is_resource($body)) {
@@ -179,8 +183,8 @@ class Proxy extends Socket
ErrorHandler::start();
$test = fwrite($this->socket, $request);
$error = ErrorHandler::stop();
if (!$test) {
throw new AdapterException\RuntimeException("Error writing request to proxy server", 0, $error);
if (! $test) {
throw new AdapterException\RuntimeException('Error writing request to proxy server', 0, $error);
}
if (is_resource($body)) {
@@ -203,18 +207,18 @@ class Proxy extends Socket
*/
protected function connectHandshake($host, $port = 443, $httpVer = '1.1', array &$headers = [])
{
$request = "CONNECT $host:$port HTTP/$httpVer\r\n" .
"Host: " . $host . "\r\n";
$request = 'CONNECT ' . $host . ':' . $port . ' HTTP/' . $httpVer . "\r\n"
. 'Host: ' . $host . "\r\n";
// Add the user-agent header
if (isset($this->config['useragent'])) {
$request .= "User-agent: " . $this->config['useragent'] . "\r\n";
$request .= 'User-agent: ' . $this->config['useragent'] . "\r\n";
}
// If the proxy-authorization header is set, send it to proxy but remove
// it from headers sent to target host
if (isset($headers['proxy-authorization'])) {
$request .= "Proxy-authorization: " . $headers['proxy-authorization'] . "\r\n";
$request .= 'Proxy-authorization: ' . $headers['proxy-authorization'] . "\r\n";
unset($headers['proxy-authorization']);
}
@@ -224,8 +228,8 @@ class Proxy extends Socket
ErrorHandler::start();
$test = fwrite($this->socket, $request);
$error = ErrorHandler::stop();
if (!$test) {
throw new AdapterException\RuntimeException("Error writing request to proxy server", 0, $error);
if (! $test) {
throw new AdapterException\RuntimeException('Error writing request to proxy server', 0, $error);
}
// Read response headers only
@@ -236,7 +240,7 @@ class Proxy extends Socket
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
if ($gotStatus) {
$response .= $line;
if (!rtrim($line)) {
if (! rtrim($line)) {
break;
}
}
@@ -245,7 +249,10 @@ class Proxy extends Socket
// Check that the response from the proxy is 200
if (Response::fromString($response)->getStatusCode() != 200) {
throw new AdapterException\RuntimeException("Unable to connect to HTTPS proxy. Server response: " . $response);
throw new AdapterException\RuntimeException(sprintf(
'Unable to connect to HTTPS proxy. Server response: %s',
$response
));
}
// If all is good, switch socket to secure mode. We have to fall back
@@ -254,7 +261,7 @@ class Proxy extends Socket
STREAM_CRYPTO_METHOD_TLS_CLIENT,
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
STREAM_CRYPTO_METHOD_SSLv2_CLIENT,
];
$success = false;
@@ -266,14 +273,14 @@ class Proxy extends Socket
}
if (! $success) {
throw new AdapterException\RuntimeException("Unable to connect to" .
" HTTPS server through proxy: could not negotiate secure connection.");
throw new AdapterException\RuntimeException(
'Unable to connect to HTTPS server through proxy: could not negotiate secure connection.'
);
}
}
/**
* Close the connection to the server
*
*/
public function close()
{
@@ -283,7 +290,6 @@ class Proxy extends Socket
/**
* Destructor: make sure the socket is disconnected
*
*/
public function __destruct()
{

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter;
@@ -12,6 +10,7 @@ namespace Zend\Http\Client\Adapter;
use Traversable;
use Zend\Http\Client\Adapter\AdapterInterface as HttpAdapter;
use Zend\Http\Client\Adapter\Exception as AdapterException;
use Zend\Http\Request;
use Zend\Http\Response;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\ErrorHandler;
@@ -39,7 +38,7 @@ class Socket implements HttpAdapter, StreamInterface
*
* @var resource|null
*/
protected $socket = null;
protected $socket;
/**
* What host/port are we connected to?
@@ -53,7 +52,7 @@ class Socket implements HttpAdapter, StreamInterface
*
* @var resource
*/
protected $outStream = null;
protected $outStream;
/**
* Parameters array
@@ -70,6 +69,7 @@ class Socket implements HttpAdapter, StreamInterface
'sslcapath' => null,
'sslallowselfsigned' => false,
'sslusecontext' => false,
'sslverifypeername' => true,
];
/**
@@ -77,14 +77,14 @@ class Socket implements HttpAdapter, StreamInterface
*
* @var string
*/
protected $method = null;
protected $method;
/**
* Stream context
*
* @var resource
*/
protected $context = null;
protected $context;
/**
* Adapter constructor, currently empty. Config is set using setOptions()
@@ -105,7 +105,7 @@ class Socket implements HttpAdapter, StreamInterface
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (!is_array($options)) {
if (! is_array($options)) {
throw new AdapterException\InvalidArgumentException(
'Array or Zend\Config object expected, got ' . gettype($options)
);
@@ -148,9 +148,10 @@ class Socket implements HttpAdapter, StreamInterface
$this->context = stream_context_create($context);
} else {
// Invalid parameter
throw new AdapterException\InvalidArgumentException(
"Expecting either a stream context resource or array, got " . gettype($context)
);
throw new AdapterException\InvalidArgumentException(sprintf(
'Expecting either a stream context resource or array, got %s',
gettype($context)
));
}
return $this;
@@ -194,45 +195,61 @@ class Socket implements HttpAdapter, StreamInterface
}
// Now, if we are not connected, connect
if (!is_resource($this->socket) || ! $this->config['keepalive']) {
if (! is_resource($this->socket) || ! $this->config['keepalive']) {
$context = $this->getStreamContext();
if ($secure || $this->config['sslusecontext']) {
if ($this->config['sslverifypeer'] !== null) {
if (!stream_context_set_option($context, 'ssl', 'verify_peer', $this->config['sslverifypeer'])) {
if (! stream_context_set_option($context, 'ssl', 'verify_peer', $this->config['sslverifypeer'])) {
throw new AdapterException\RuntimeException('Unable to set sslverifypeer option');
}
}
if ($this->config['sslcafile']) {
if (!stream_context_set_option($context, 'ssl', 'cafile', $this->config['sslcafile'])) {
if (! stream_context_set_option($context, 'ssl', 'cafile', $this->config['sslcafile'])) {
throw new AdapterException\RuntimeException('Unable to set sslcafile option');
}
}
if ($this->config['sslcapath']) {
if (!stream_context_set_option($context, 'ssl', 'capath', $this->config['sslcapath'])) {
if (! stream_context_set_option($context, 'ssl', 'capath', $this->config['sslcapath'])) {
throw new AdapterException\RuntimeException('Unable to set sslcapath option');
}
}
if ($this->config['sslallowselfsigned'] !== null) {
if (!stream_context_set_option($context, 'ssl', 'allow_self_signed', $this->config['sslallowselfsigned'])) {
if (! stream_context_set_option(
$context,
'ssl',
'allow_self_signed',
$this->config['sslallowselfsigned']
)) {
throw new AdapterException\RuntimeException('Unable to set sslallowselfsigned option');
}
}
if ($this->config['sslcert'] !== null) {
if (!stream_context_set_option($context, 'ssl', 'local_cert', $this->config['sslcert'])) {
if (! stream_context_set_option($context, 'ssl', 'local_cert', $this->config['sslcert'])) {
throw new AdapterException\RuntimeException('Unable to set sslcert option');
}
}
if ($this->config['sslpassphrase'] !== null) {
if (!stream_context_set_option($context, 'ssl', 'passphrase', $this->config['sslpassphrase'])) {
if (! stream_context_set_option($context, 'ssl', 'passphrase', $this->config['sslpassphrase'])) {
throw new AdapterException\RuntimeException('Unable to set sslpassphrase option');
}
}
if ($this->config['sslverifypeername'] !== null) {
if (! stream_context_set_option(
$context,
'ssl',
'verify_peer_name',
$this->config['sslverifypeername']
)) {
throw new AdapterException\RuntimeException('Unable to set sslverifypeername option');
}
}
}
$flags = STREAM_CLIENT_CONNECT;
@@ -240,18 +257,23 @@ class Socket implements HttpAdapter, StreamInterface
$flags |= STREAM_CLIENT_PERSISTENT;
}
if (isset($this->config['connecttimeout'])) {
$connectTimeout = $this->config['connecttimeout'];
} else {
$connectTimeout = $this->config['timeout'];
}
ErrorHandler::start();
$this->socket = stream_socket_client(
$host . ':' . $port,
$errno,
$errstr,
(int) $this->config['timeout'],
(int) $connectTimeout,
$flags,
$context
);
$error = ErrorHandler::stop();
if (!$this->socket) {
if (! $this->socket) {
$this->close();
throw new AdapterException\RuntimeException(
sprintf(
@@ -266,7 +288,7 @@ class Socket implements HttpAdapter, StreamInterface
}
// Set the stream timeout
if (!stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
if (! stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
throw new AdapterException\RuntimeException('Unable to set the connection timeout');
}
@@ -280,12 +302,12 @@ class Socket implements HttpAdapter, StreamInterface
ErrorHandler::start();
$test = stream_socket_enable_crypto($this->socket, true, $sslCryptoMethod);
$error = ErrorHandler::stop();
if (!$test || $error) {
if (! $test || $error) {
// Error handling is kind of difficult when it comes to SSL
$errorString = '';
if (extension_loaded('openssl')) {
while (($sslError = openssl_error_string()) != false) {
$errorString .= "; SSL error: $sslError";
$errorString .= sprintf('; SSL error: %s', $sslError);
}
}
$this->close();
@@ -293,16 +315,18 @@ class Socket implements HttpAdapter, StreamInterface
if ((! $errorString) && $this->config['sslverifypeer']) {
// There's good chance our error is due to sslcapath not being properly set
if (! ($this->config['sslcafile'] || $this->config['sslcapath'])) {
$errorString = 'make sure the "sslcafile" or "sslcapath" option are properly set for the environment.';
} elseif ($this->config['sslcafile'] && !is_file($this->config['sslcafile'])) {
$errorString = 'make sure the "sslcafile" or "sslcapath" option are properly set for the '
. 'environment.';
} elseif ($this->config['sslcafile'] && ! is_file($this->config['sslcafile'])) {
$errorString = 'make sure the "sslcafile" option points to a valid SSL certificate file';
} elseif ($this->config['sslcapath'] && !is_dir($this->config['sslcapath'])) {
$errorString = 'make sure the "sslcapath" option points to a valid SSL certificate directory';
} elseif ($this->config['sslcapath'] && ! is_dir($this->config['sslcapath'])) {
$errorString = 'make sure the "sslcapath" option points to a valid SSL certificate '
. 'directory';
}
}
if ($errorString) {
$errorString = ": $errorString";
$errorString = sprintf(': %s', $errorString);
}
throw new AdapterException\RuntimeException(sprintf(
@@ -312,7 +336,7 @@ class Socket implements HttpAdapter, StreamInterface
), 0, $error);
}
$host = $this->config['ssltransport'] . "://" . $host;
$host = $this->config['ssltransport'] . '://' . $host;
} else {
$host = 'tcp://' . $host;
}
@@ -355,12 +379,12 @@ class Socket implements HttpAdapter, StreamInterface
if ($uri->getQuery()) {
$path .= '?' . $uri->getQuery();
}
$request = "{$method} {$path} HTTP/{$httpVer}\r\n";
$request = $method . ' ' . $path . ' HTTP/' . $httpVer . "\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) {
$v = ucfirst($k) . ": $v";
$v = ucfirst($k) . ': ' . $v;
}
$request .= "$v\r\n";
$request .= $v . "\r\n";
}
if (is_resource($body)) {
@@ -411,7 +435,7 @@ class Socket implements HttpAdapter, StreamInterface
$this->_checkSocketReadTimeout();
$responseObj= Response::fromString($response);
$responseObj = Response::fromString($response);
$statusCode = $responseObj->getStatusCode();
@@ -427,8 +451,10 @@ class Socket implements HttpAdapter, StreamInterface
* Responses to HEAD requests and 204 or 304 responses are not expected
* to have a body - stop reading here
*/
if ($statusCode == 304 || $statusCode == 204 ||
$this->method == \Zend\Http\Request::METHOD_HEAD) {
if ($statusCode == 304
|| $statusCode == 204
|| $this->method == Request::METHOD_HEAD
) {
// Close the connection if requested to do so by the server
$connection = $headers->get('connection');
if ($connection && $connection->getFieldValue() == 'close') {
@@ -452,8 +478,10 @@ class Socket implements HttpAdapter, StreamInterface
$chunksize = trim($line);
if (! ctype_xdigit($chunksize)) {
$this->close();
throw new AdapterException\RuntimeException('Invalid chunk size "' .
$chunksize . '" unable to read chunked body');
throw new AdapterException\RuntimeException(sprintf(
'Invalid chunk size "%s" unable to read chunked body',
$chunksize
));
}
// Convert the hexadecimal value to plain integer
@@ -488,14 +516,16 @@ class Socket implements HttpAdapter, StreamInterface
ErrorHandler::stop();
$this->_checkSocketReadTimeout();
if (!$this->outStream) {
if (! $this->outStream) {
$response .= $chunk;
}
} while ($chunksize > 0);
} else {
$this->close();
throw new AdapterException\RuntimeException('Cannot handle "' .
$transferEncoding->getFieldValue() . '" transfer encoding');
throw new AdapterException\RuntimeException(sprintf(
'Cannot handle "%s" transfer encoding',
$transferEncoding->getFieldValue()
));
}
// We automatically decode chunked-messages when writing to a stream
@@ -590,15 +620,17 @@ class Socket implements HttpAdapter, StreamInterface
*
* @throws AdapterException\TimeoutException with READ_TIMEOUT code
*/
// @codingStandardsIgnoreStart
protected function _checkSocketReadTimeout()
{
// @codingStandardsIgnoreEnd
if ($this->socket) {
$info = stream_get_meta_data($this->socket);
$timedout = $info['timed_out'];
if ($timedout) {
$this->close();
throw new AdapterException\TimeoutException(
"Read timed out after {$this->config['timeout']} seconds",
sprintf('Read timed out after %d seconds', $this->config['timeout']),
AdapterException\TimeoutException::READ_TIMEOUT
);
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Adapter;
@@ -132,12 +130,12 @@ class Test implements AdapterInterface
if ($uri->getQuery()) {
$path .= '?' . $uri->getQuery();
}
$request = "{$method} {$path} HTTP/{$httpVer}\r\n";
$request = $method . ' ' . $path . ' HTTP/' . $httpVer . "\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) {
$v = ucfirst($k) . ": $v";
$v = ucfirst($k) . ': ' . $v;
}
$request .= "$v\r\n";
$request .= $v . "\r\n";
}
// Add the request body
@@ -209,7 +207,8 @@ class Test implements AdapterInterface
{
if ($index < 0 || $index >= count($this->responses)) {
throw new Exception\OutOfRangeException(
'Index out of range of response buffer size');
'Index out of range of response buffer size'
);
}
$this->responseIndex = $index;
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Exception;

View File

@@ -1,18 +1,14 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Exception;
use Zend\Http\Exception;
/**
*/
class InvalidArgumentException extends Exception\InvalidArgumentException implements
ExceptionInterface
{

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Exception;

View File

@@ -1,18 +1,14 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Client\Exception;
use Zend\Http\Exception;
/**
*/
class RuntimeException extends Exception\RuntimeException implements
ExceptionInterface
{

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http;
@@ -27,7 +25,7 @@ class ClientStatic
*/
protected static function getStaticClient($options = null)
{
if (!isset(static::$client) || $options !== null) {
if (! isset(static::$client) || $options !== null) {
static::$client = new Client(null, $options);
}
return static::$client;
@@ -49,19 +47,19 @@ class ClientStatic
return false;
}
$request= new Request();
$request = new Request();
$request->setUri($url);
$request->setMethod(Request::METHOD_GET);
if (!empty($query) && is_array($query)) {
if (! empty($query) && is_array($query)) {
$request->getQuery()->fromArray($query);
}
if (!empty($headers) && is_array($headers)) {
if (! empty($headers) && is_array($headers)) {
$request->getHeaders()->addHeaders($headers);
}
if (!empty($body)) {
if (! empty($body)) {
$request->setContent($body);
}
@@ -85,25 +83,25 @@ class ClientStatic
return false;
}
$request= new Request();
$request = new Request();
$request->setUri($url);
$request->setMethod(Request::METHOD_POST);
if (!empty($params) && is_array($params)) {
if (! empty($params) && is_array($params)) {
$request->getPost()->fromArray($params);
} else {
throw new Exception\InvalidArgumentException('The array of post parameters is empty');
}
if (!isset($headers['Content-Type'])) {
if (! isset($headers['Content-Type'])) {
$headers['Content-Type'] = Client::ENC_URLENCODED;
}
if (!empty($headers) && is_array($headers)) {
if (! empty($headers) && is_array($headers)) {
$request->getHeaders()->addHeaders($headers);
}
if (!empty($body)) {
if (! empty($body)) {
$request->setContent($body);
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http;
@@ -35,19 +33,16 @@ class Cookies extends Headers
{
/**
* Return cookie(s) as a Zend\Http\Cookie object
*
*/
const COOKIE_OBJECT = 0;
/**
* Return cookie(s) as a string (suitable for sending in an HTTP request)
*
*/
const COOKIE_STRING_ARRAY = 1;
/**
* Return all cookies as one long string (suitable for sending in an HTTP request)
*
*/
const COOKIE_STRING_CONCAT = 2;
@@ -66,7 +61,7 @@ class Cookies extends Headers
/**
* @var \Zend\Http\Headers
*/
protected $headers = null;
protected $headers;
/**
* @var array
@@ -104,10 +99,10 @@ class Cookies extends Headers
if ($cookie instanceof SetCookie) {
$domain = $cookie->getDomain();
$path = $cookie->getPath();
if (!isset($this->cookies[$domain])) {
if (! isset($this->cookies[$domain])) {
$this->cookies[$domain] = [];
}
if (!isset($this->cookies[$domain][$path])) {
if (! isset($this->cookies[$domain][$path])) {
$this->cookies[$domain][$path] = [];
}
$this->cookies[$domain][$path][$cookie->getName()] = $cookie;
@@ -168,8 +163,8 @@ class Cookies extends Headers
) {
if (is_string($uri)) {
$uri = Uri\UriFactory::factory($uri, 'http');
} elseif (!$uri instanceof Uri\Uri) {
throw new Exception\InvalidArgumentException("Invalid URI string or object passed");
} elseif (! $uri instanceof Uri\Uri) {
throw new Exception\InvalidArgumentException('Invalid URI string or object passed');
}
$host = $uri->getHost();
@@ -208,7 +203,7 @@ class Cookies extends Headers
{
if (is_string($uri)) {
$uri = Uri\UriFactory::factory($uri, 'http');
} elseif (!$uri instanceof Uri\Uri) {
} elseif (! $uri instanceof Uri\Uri) {
throw new Exception\InvalidArgumentException('Invalid URI specified');
}
@@ -237,7 +232,10 @@ class Cookies extends Headers
return $cookie->__toString();
default:
throw new Exception\InvalidArgumentException("Invalid value passed for \$retAs: {$retAs}");
throw new Exception\InvalidArgumentException(sprintf(
'Invalid value passed for $retAs: %s',
$retAs
));
}
}
@@ -252,8 +250,10 @@ class Cookies extends Headers
* @param int $retAs What value to return
* @return array|string
*/
// @codingStandardsIgnoreStart
protected function _flattenCookiesArray($ptr, $retAs = self::COOKIE_OBJECT)
{
// @codingStandardsIgnoreEnd
if (is_array($ptr)) {
$ret = ($retAs == self::COOKIE_STRING_CONCAT ? '' : []);
foreach ($ptr as $item) {
@@ -287,8 +287,10 @@ class Cookies extends Headers
* @param string $domain
* @return array
*/
// @codingStandardsIgnoreStart
protected function _matchDomain($domain)
{
// @codingStandardsIgnoreEnd
$ret = [];
foreach (array_keys($this->cookies) as $cdom) {
@@ -307,8 +309,10 @@ class Cookies extends Headers
* @param string $path
* @return array
*/
// @codingStandardsIgnoreStart
protected function _matchPath($domains, $path)
{
// @codingStandardsIgnoreEnd
$ret = [];
foreach ($domains as $dom => $pathsArray) {

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Exception;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Exception;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Exception;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Exception;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -39,7 +37,6 @@ use stdClass;
abstract class AbstractAccept implements HeaderInterface
{
/**
*
* @var stdClass[]
*/
protected $fieldValueParts = [];
@@ -99,8 +96,8 @@ abstract class AbstractAccept implements HeaderInterface
public function getFieldValuePartsFromHeaderLine($headerLine)
{
// process multiple accept values, they may be between quotes
if (!preg_match_all('/(?:[^,"]|"(?:[^\\\"]|\\\.)*")+/', $headerLine, $values)
|| !isset($values[0])
if (! preg_match_all('/(?:[^,"]|"(?:[^\\\"]|\\\.)*")+/', $headerLine, $values)
|| ! isset($values[0])
) {
throw new Exception\InvalidArgumentException(
'Invalid header line for ' . $this->getFieldName() . ' header string'
@@ -139,14 +136,14 @@ abstract class AbstractAccept implements HeaderInterface
$subtype = '*';
return (object) [
'typeString' => trim($fieldValuePart),
'type' => $type,
'subtype' => $subtype,
'subtypeRaw' => $subtypeWhole,
'format' => $format,
'priority' => isset($params['q']) ? $params['q'] : 1,
'params' => $params,
'raw' => trim($raw)
'typeString' => trim($fieldValuePart),
'type' => $type,
'subtype' => $subtype,
'subtypeRaw' => $subtypeWhole,
'format' => $format,
'priority' => isset($params['q']) ? $params['q'] : 1,
'params' => $params,
'raw' => trim($raw),
];
}
@@ -219,8 +216,7 @@ abstract class AbstractAccept implements HeaderInterface
*/
protected function assembleAcceptParam(&$value, $key)
{
$separators = ['(', ')', '<', '>', '@', ',', ';', ':',
'/', '[', ']', '?', '=', '{', '}', ' ', "\t"];
$separators = ['(', ')', '<', '>', '@', ',', ';', ':', '/', '[', ']', '?', '=', '{', '}', ' ', "\t"];
$escaped = preg_replace_callback(
'/[[:cntrl:]"\\\\]/', // escape cntrl, ", \
@@ -230,7 +226,7 @@ abstract class AbstractAccept implements HeaderInterface
$value
);
if ($escaped == $value && !array_intersect(str_split($value), $separators)) {
if ($escaped == $value && ! array_intersect(str_split($value), $separators)) {
$value = $key . ($value ? '=' . $value : '');
} else {
$value = $key . ($value ? '="' . $escaped . '"' : '');
@@ -250,7 +246,7 @@ abstract class AbstractAccept implements HeaderInterface
*/
protected function addType($type, $priority = 1, array $params = [])
{
if (!preg_match($this->regexAddType, $type)) {
if (! preg_match($this->regexAddType, $type)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a valid type; received "%s"',
__METHOD__,
@@ -258,7 +254,7 @@ abstract class AbstractAccept implements HeaderInterface
));
}
if (!is_int($priority) && !is_float($priority) && !is_numeric($priority)
if (! is_int($priority) && ! is_float($priority) && ! is_numeric($priority)
|| $priority > 1 || $priority < 0
) {
throw new Exception\InvalidArgumentException(sprintf(
@@ -315,8 +311,8 @@ abstract class AbstractAccept implements HeaderInterface
}
if ($left->type == $right->type) {
if (($left->subtype == $right->subtype || ($right->subtype == '*' || $left->subtype == '*')) &&
($left->format == $right->format || $right->format == '*' || $left->format == '*')
if (($left->subtype == $right->subtype || ($right->subtype == '*' || $left->subtype == '*'))
&& ($left->format == $right->format || $right->format == '*' || $left->format == '*')
) {
if ($this->matchAcceptParams($left, $right)) {
$left->setMatchedAgainst($right);
@@ -349,10 +345,9 @@ abstract class AbstractAccept implements HeaderInterface
$pieces
);
if (count($pieces) == 3 &&
(version_compare($pieces[1], $match1->params[$key], '<=') xor
version_compare($pieces[2], $match1->params[$key], '>=')
)
if (count($pieces) == 3
&& (version_compare($pieces[1], $match1->params[$key], '<=')
xor version_compare($pieces[2], $match1->params[$key], '>='))
) {
return false;
}
@@ -366,7 +361,7 @@ abstract class AbstractAccept implements HeaderInterface
}
}
if (!$good) {
if (! $good) {
return false;
}
} elseif ($match1->params[$key] != $value) {
@@ -411,7 +406,8 @@ abstract class AbstractAccept implements HeaderInterface
*/
protected function sortFieldValueParts()
{
$sort = function ($a, $b) { // If A has higher precedence than B, return -1.
$sort = function ($a, $b) {
// If A has higher precedence than B, return -1.
if ($a->priority > $b->priority) {
return -1;
} elseif ($a->priority < $b->priority) {
@@ -434,7 +430,7 @@ abstract class AbstractAccept implements HeaderInterface
return 1;
}
//@todo count number of dots in case of type==application in subtype
// @todo count number of dots in case of type==application in subtype
// So far they're still the same. Longest string length may be more specific
if (strlen($a->raw) == strlen($b->raw)) {
@@ -452,7 +448,7 @@ abstract class AbstractAccept implements HeaderInterface
*/
public function getPrioritized()
{
if (!$this->sorted) {
if (! $this->sorted) {
$this->sortFieldValueParts();
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -41,7 +39,7 @@ abstract class AbstractDate implements HeaderInterface
*
* @var DateTime
*/
protected $date = null;
protected $date;
/**
* Date output format
@@ -134,10 +132,11 @@ abstract class AbstractDate implements HeaderInterface
*/
public static function setDateFormat($format)
{
if (!isset(static::$dateFormats[$format])) {
throw new Exception\InvalidArgumentException(
"No constant defined for provided date format: {$format}"
);
if (! isset(static::$dateFormats[$format])) {
throw new Exception\InvalidArgumentException(sprintf(
'No constant defined for provided date format: %s',
$format
));
}
static::$dateFormat = static::$dateFormats[$format];
@@ -172,7 +171,7 @@ abstract class AbstractDate implements HeaderInterface
$e
);
}
} elseif (!($date instanceof DateTime)) {
} elseif (! ($date instanceof DateTime)) {
throw new Exception\InvalidArgumentException('Date must be an instance of \DateTime or a string');
}
@@ -226,7 +225,7 @@ abstract class AbstractDate implements HeaderInterface
$e
);
}
} elseif (!($date instanceof DateTime)) {
} elseif (! ($date instanceof DateTime)) {
throw new Exception\InvalidArgumentException('Date must be an instance of \DateTime or a string');
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -31,7 +29,7 @@ abstract class AbstractLocation implements HeaderInterface
*
* @var UriInterface
*/
protected $uri = null;
protected $uri;
/**
* Create location-based header from string
@@ -79,7 +77,7 @@ abstract class AbstractLocation implements HeaderInterface
$e
);
}
} elseif (!($uri instanceof UriInterface)) {
} elseif (! ($uri instanceof UriInterface)) {
throw new Exception\InvalidArgumentException('URI must be an instance of Zend\Uri\Http or a string');
}
$this->uri = $uri;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header\Accept\FieldValuePart;
@@ -12,7 +10,6 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
/**
* Field Value Part
*
*
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
*/
abstract class AbstractFieldValuePart
@@ -30,7 +27,6 @@ abstract class AbstractFieldValuePart
protected $matchedAgainst;
/**
*
* @param object $internalValues
*/
public function __construct($internalValues)
@@ -61,7 +57,6 @@ abstract class AbstractFieldValuePart
}
/**
*
* @return object
*/
protected function getInternalValues()
@@ -102,8 +97,7 @@ abstract class AbstractFieldValuePart
}
/**
*
* @param mixed
* @param mixed $key
* @return mixed
*/
public function __get($key)

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header\Accept\FieldValuePart;
@@ -12,7 +10,6 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
/**
* Field Value Part
*
*
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
*/
class AcceptFieldValuePart extends AbstractFieldValuePart

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header\Accept\FieldValuePart;
@@ -12,13 +10,11 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
/**
* Field Value Part
*
*
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
*/
class CharsetFieldValuePart extends AbstractFieldValuePart
{
/**
*
* @return string
*/
public function getCharset()

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header\Accept\FieldValuePart;
@@ -12,13 +10,11 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
/**
* Field Value Part
*
*
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
*/
class EncodingFieldValuePart extends AbstractFieldValuePart
{
/**
*
* @return string
*/
public function getEncoding()

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header\Accept\FieldValuePart;
@@ -12,7 +10,6 @@ namespace Zend\Http\Header\Accept\FieldValuePart;
/**
* Field Value Part
*
*
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
*/
class LanguageFieldValuePart extends AbstractFieldValuePart

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -86,7 +84,7 @@ class AcceptLanguage extends AbstractAccept
}
if (strpos($fieldValuePart, '-')) {
$subtypeWhole = $format = $subtype = trim(substr($fieldValuePart, strpos($fieldValuePart, '-')+1));
$subtypeWhole = $format = $subtype = trim(substr($fieldValuePart, strpos($fieldValuePart, '-') + 1));
} else {
$subtypeWhole = '';
$format = '*';
@@ -94,14 +92,14 @@ class AcceptLanguage extends AbstractAccept
}
$aggregated = [
'typeString' => trim($fieldValuePart),
'type' => $type,
'subtype' => $subtype,
'subtypeRaw' => $subtypeWhole,
'format' => $format,
'priority' => isset($params['q']) ? $params['q'] : 1,
'params' => $params,
'raw' => trim($raw)
'typeString' => trim($fieldValuePart),
'type' => $type,
'subtype' => $subtype,
'subtypeRaw' => $subtypeWhole,
'format' => $format,
'priority' => isset($params['q']) ? $params['q'] : 1,
'params' => $params,
'raw' => trim($raw),
];
return new FieldValuePart\LanguageFieldValuePart((object) $aggregated);

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -17,7 +15,7 @@ class AuthenticationInfo implements HeaderInterface
{
/**
* @var string
*/
*/
protected $value;
public static function fromString($headerLine)

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -41,7 +39,7 @@ class CacheControl implements HeaderInterface
// check to ensure proper header type for this factory
if (strtolower($name) !== 'cache-control') {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid header line for Cache-Control string: ""',
'Invalid header line for Cache-Control string: "%s"',
$name
));
}
@@ -145,9 +143,9 @@ class CacheControl implements HeaderInterface
$parts[] = $key;
} else {
if (preg_match('#[^a-zA-Z0-9._-]#', $value)) {
$value = '"' . $value.'"';
$value = '"' . $value . '"';
}
$parts[] = "$key=$value";
$parts[] = $key . '=' . $value;
}
}
return implode(', ', $parts);
@@ -223,7 +221,6 @@ class CacheControl implements HeaderInterface
default:
throw new Exception\InvalidArgumentException('expected SEPARATOR or END');
}
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -27,7 +25,7 @@ class Connection implements HeaderInterface
protected $value = self::CONNECTION_KEEP_ALIVE;
/**
* @param $headerLine
* @param string $headerLine
* @return Connection
* @throws Exception\InvalidArgumentException
*/

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -17,7 +15,7 @@ class ContentDisposition implements HeaderInterface
{
/**
* @var string
*/
*/
protected $value;
public static function fromString($headerLine)

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -73,6 +71,12 @@ class ContentSecurityPolicy implements HeaderInterface
));
}
if (empty($sources)) {
if ('report-uri' === $name) {
if (isset($this->directives[$name])) {
unset($this->directives[$name]);
}
return $this;
}
$this->directives[$name] = "'none'";
return $this;
}
@@ -109,7 +113,7 @@ class ContentSecurityPolicy implements HeaderInterface
$token = trim($token);
if ($token) {
list($directiveName, $directiveValue) = explode(' ', $token, 2);
if (!isset($header->directives[$directiveName])) {
if (! isset($header->directives[$directiveName])) {
$header->setDirective($directiveName, [$directiveValue]);
}
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -50,15 +48,15 @@ class ContentType implements HeaderInterface
));
}
$parts = explode(';', $value);
$mediaType = array_shift($parts);
$header = new static($value, trim($mediaType));
$parts = explode(';', $value);
$mediaType = array_shift($parts);
$header = new static($value, trim($mediaType));
if (count($parts) > 0) {
$parameters = [];
foreach ($parts as $parameter) {
$parameter = trim($parameter);
if (!preg_match('/^(?P<key>[^\s\=]+)\="?(?P<value>[^\s\"]*)"?$/', $parameter, $matches)) {
if (! preg_match('/^(?P<key>[^\s\=]+)\="?(?P<value>[^\s\"]*)"?$/', $parameter, $matches)) {
continue;
}
$parameters[$matches['key']] = $matches['value'];
@@ -228,7 +226,7 @@ class ContentType implements HeaderInterface
if (isset($this->parameters['charset'])) {
return $this->parameters['charset'];
}
return;
return null;
}
/**
@@ -282,7 +280,7 @@ class ContentType implements HeaderInterface
*/
protected function getMediaTypeObjectFromString($string)
{
if (!is_string($string)) {
if (! is_string($string)) {
throw new Exception\InvalidArgumentException(sprintf(
'Non-string mediatype "%s" provided',
(is_object($string) ? get_class($string) : gettype($string))
@@ -300,7 +298,7 @@ class ContentType implements HeaderInterface
$type = array_shift($parts);
$subtype = array_shift($parts);
$format = $subtype;
if (strstr($subtype, '+')) {
if (false !== strpos($subtype, '+')) {
$parts = explode('+', $subtype, 2);
$subtype = array_shift($parts);
$format = array_shift($parts);
@@ -337,7 +335,7 @@ class ContentType implements HeaderInterface
// Is the right side a partial wildcard?
if ('*' == substr($right->subtype, -1)) {
// validate partial-wildcard subtype
if (!$this->validatePartialWildcard($right->subtype, $left->subtype)) {
if (! $this->validatePartialWildcard($right->subtype, $left->subtype)) {
return false;
}
// Finally, verify format is valid

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -97,13 +95,28 @@ class Cookie extends ArrayObject implements HeaderInterface
{
$nvPairs = [];
foreach ($this as $name => $value) {
foreach ($this->flattenCookies($this) as $name => $value) {
$nvPairs[] = $name . '=' . (($this->encodeValue) ? urlencode($value) : $value);
}
return implode('; ', $nvPairs);
}
protected function flattenCookies($data, $prefix = null)
{
$result = [];
foreach ($data as $key => $value) {
$key = $prefix ? $prefix . '[' . $key . ']' : $key;
if (is_array($value)) {
$result = array_merge($result, $this->flattenCookies($value, $key));
} else {
$result[$key] = $value;
}
}
return $result;
}
public function toString()
{
return 'Cookie: ' . $this->getFieldValue();

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header\Exception;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header\Exception;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header\Exception;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header\Exception;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -25,4 +23,12 @@ class Expires extends AbstractDate
{
return 'Expires';
}
public function setDate($date)
{
if ($date === '0' || $date === 0) {
$date = date(DATE_W3C, 0); // Thu, 01 Jan 1970 00:00:00 GMT
}
return parent::setDate($date);
}
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,29 +1,26 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
/**
* Content-Location Header
*
*/
*/
class GenericHeader implements HeaderInterface
{
/**
* @var string
*/
protected $fieldName = null;
protected $fieldName;
/**
* @var string
*/
protected $fieldValue = null;
protected $fieldValue;
/**
* Factory to generate a header object from a string
@@ -88,7 +85,7 @@ class GenericHeader implements HeaderInterface
*/
public function setFieldName($fieldName)
{
if (!is_string($fieldName) || empty($fieldName)) {
if (! is_string($fieldName) || empty($fieldName)) {
throw new Exception\InvalidArgumentException('Header name must be a string');
}
@@ -101,7 +98,7 @@ class GenericHeader implements HeaderInterface
* tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
* "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
*/
if (!preg_match('/^[!#$%&\'*+\-\.\^_`|~0-9a-zA-Z]+$/', $fieldName)) {
if (! preg_match('/^[!#$%&\'*+\-\.\^_`|~0-9a-zA-Z]+$/', $fieldName)) {
throw new Exception\InvalidArgumentException(
'Header name must be a valid RFC 7230 (section 3.2) field-name.'
);

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -32,8 +30,10 @@ class GenericMultiHeader extends GenericHeader implements MultipleHeaderInterfac
$name = $this->getFieldName();
$values = [$this->getFieldValue()];
foreach ($headers as $header) {
if (!$header instanceof static) {
throw new Exception\InvalidArgumentException('This method toStringMultipleHeaders was expecting an array of headers of the same type');
if (! $header instanceof static) {
throw new Exception\InvalidArgumentException(
'This method toStringMultipleHeaders was expecting an array of headers of the same type'
);
}
$values[] = $header->getFieldValue();
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -17,7 +15,7 @@ class IfRange implements HeaderInterface
{
/**
* @var string
*/
*/
protected $value;
public static function fromString($headerLine)

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -32,7 +30,7 @@ class Origin implements HeaderInterface
}
$uri = UriFactory::factory($value);
if (!$uri->isValid()) {
if (! $uri->isValid()) {
throw new Exception\InvalidArgumentException('Invalid header value for Origin key: "' . $name . '"');
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -65,7 +63,7 @@ class ProxyAuthenticate implements MultipleHeaderInterface
{
$strings = [$this->toString()];
foreach ($headers as $header) {
if (!$header instanceof ProxyAuthenticate) {
if (! $header instanceof ProxyAuthenticate) {
throw new Exception\RuntimeException(
'The ProxyAuthenticate multiple header implementation can only accept'
. ' an array of ProxyAuthenticate headers'

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -17,7 +15,7 @@ class Refresh implements HeaderInterface
{
/**
* @var string
*/
*/
protected $value;
public static function fromString($headerLine)

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -24,56 +22,56 @@ class SetCookie implements MultipleHeaderInterface
*
* @var string|null
*/
protected $name = null;
protected $name;
/**
* Cookie value
*
* @var string|null
*/
protected $value = null;
protected $value;
/**
* Version
*
* @var int|null
*/
protected $version = null;
protected $version;
/**
* Max Age
*
* @var int|null
*/
protected $maxAge = null;
protected $maxAge;
/**
* Cookie expiry date
*
* @var int|null
*/
protected $expires = null;
protected $expires;
/**
* Cookie domain
*
* @var string|null
*/
protected $domain = null;
protected $domain;
/**
* Cookie path
*
* @var string|null
*/
protected $path = null;
protected $path;
/**
* Whether the cookie is secure or not
*
* @var bool|null
*/
protected $secure = null;
protected $secure;
/**
* If the value need to be quoted or not
@@ -85,7 +83,7 @@ class SetCookie implements MultipleHeaderInterface
/**
* @var bool|null
*/
protected $httponly = null;
protected $httponly;
/**
* @static
@@ -101,13 +99,13 @@ class SetCookie implements MultipleHeaderInterface
if ($setCookieProcessor === null) {
$setCookieClass = get_called_class();
$setCookieProcessor = function ($headerLine) use ($setCookieClass) {
$header = new $setCookieClass;
$header = new $setCookieClass();
$keyValuePairs = preg_split('#;\s*#', $headerLine);
foreach ($keyValuePairs as $keyValue) {
if (preg_match('#^(?P<headerKey>[^=]+)=\s*("?)(?P<headerValue>[^"]*)\2#', $keyValue, $matches)) {
$headerKey = $matches['headerKey'];
$headerValue= $matches['headerValue'];
$headerValue = $matches['headerValue'];
} else {
$headerKey = $keyValue;
$headerValue = null;
@@ -141,7 +139,7 @@ class SetCookie implements MultipleHeaderInterface
$header->setVersion((int) $headerValue);
break;
case 'maxage':
$header->setMaxAge((int) $headerValue);
$header->setMaxAge($headerValue);
break;
default:
// Intentionally omitted
@@ -156,7 +154,7 @@ class SetCookie implements MultipleHeaderInterface
HeaderValue::assertValid($value);
// some sites return set-cookie::value, this is to get rid of the second :
$name = (strtolower($name) =='set-cookie:') ? 'set-cookie' : $name;
$name = strtolower($name) == 'set-cookie:' ? 'set-cookie' : $name;
// check to ensure proper header type for this factory
if (strtolower($name) !== 'set-cookie') {
@@ -235,7 +233,7 @@ class SetCookie implements MultipleHeaderInterface
$value = urlencode($this->getValue());
if ($this->hasQuoteFieldValue()) {
$value = '"'. $value . '"';
$value = '"' . $value . '"';
}
$fieldValue = $this->getName() . '=' . $value;
@@ -246,7 +244,7 @@ class SetCookie implements MultipleHeaderInterface
}
$maxAge = $this->getMaxAge();
if ($maxAge!==null) {
if ($maxAge !== null) {
$fieldValue .= '; Max-Age=' . $maxAge;
}
@@ -323,7 +321,7 @@ class SetCookie implements MultipleHeaderInterface
*/
public function setVersion($version)
{
if ($version !== null && !is_int($version)) {
if ($version !== null && ! is_int($version)) {
throw new Exception\InvalidArgumentException('Invalid Version number specified');
}
$this->version = $version;
@@ -344,15 +342,15 @@ class SetCookie implements MultipleHeaderInterface
* Set Max-Age
*
* @param int $maxAge
* @throws Exception\InvalidArgumentException
* @return SetCookie
*/
public function setMaxAge($maxAge)
{
if ($maxAge !== null && (!is_int($maxAge) || ($maxAge < 0))) {
throw new Exception\InvalidArgumentException('Invalid Max-Age number specified');
if ($maxAge === null || ! is_numeric($maxAge)) {
return $this;
}
$this->maxAge = $maxAge;
$this->maxAge = max(0, (int) $maxAge);
return $this;
}
@@ -392,7 +390,7 @@ class SetCookie implements MultipleHeaderInterface
$tsExpires = strtotime($expires);
// if $tsExpires is invalid and PHP is compiled as 32bit. Check if it fail reason is the 2038 bug
if (!is_int($tsExpires) && PHP_INT_SIZE === 4) {
if (! is_int($tsExpires) && PHP_INT_SIZE === 4) {
$dateTime = new DateTime($expires);
if ($dateTime->format('Y') > 2038) {
$tsExpires = PHP_INT_MAX;
@@ -400,7 +398,7 @@ class SetCookie implements MultipleHeaderInterface
}
}
if (!is_int($tsExpires) || $tsExpires < 0) {
if (! is_int($tsExpires) || $tsExpires < 0) {
throw new Exception\InvalidArgumentException('Invalid expires time specified');
}
@@ -567,7 +565,7 @@ class SetCookie implements MultipleHeaderInterface
return false;
}
if ($this->secure && $this->isSecure()!==$isSecure) {
if ($this->secure && $this->isSecure() !== $isSecure) {
return false;
}
@@ -590,7 +588,7 @@ class SetCookie implements MultipleHeaderInterface
}
// Make sure we have a valid Zend_Uri_Http object
if (! ($uri->isValid() && ($uri->getScheme() == 'http' || $uri->getScheme() =='https'))) {
if (! ($uri->isValid() && ($uri->getScheme() == 'http' || $uri->getScheme() == 'https'))) {
throw new Exception\InvalidArgumentException('Passed URI is not a valid HTTP or HTTPS URI');
}
@@ -634,8 +632,8 @@ class SetCookie implements MultipleHeaderInterface
$cookieDomain = strtolower($cookieDomain);
$host = strtolower($host);
// Check for either exact match or suffix match
return ($cookieDomain == $host ||
preg_match('/' . preg_quote($cookieDomain) . '$/', $host));
return $cookieDomain == $host
|| preg_match('/' . preg_quote($cookieDomain) . '$/', $host);
}
/**
@@ -662,7 +660,7 @@ class SetCookie implements MultipleHeaderInterface
$headerLine = $this->toString();
/* @var $header SetCookie */
foreach ($headers as $header) {
if (!$header instanceof SetCookie) {
if (! $header instanceof SetCookie) {
throw new Exception\RuntimeException(
'The SetCookie multiple header implementation can only accept an array of SetCookie headers'
);

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -17,7 +15,7 @@ class Trailer implements HeaderInterface
{
/**
* @var string
*/
*/
protected $value;
public static function fromString($headerLine)

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -17,7 +15,7 @@ class TransferEncoding implements HeaderInterface
{
/**
* @var string
*/
*/
protected $value;
public static function fromString($headerLine)

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;
@@ -65,7 +63,7 @@ class WWWAuthenticate implements MultipleHeaderInterface
{
$strings = [$this->toString()];
foreach ($headers as $header) {
if (!$header instanceof WWWAuthenticate) {
if (! $header instanceof WWWAuthenticate) {
throw new Exception\RuntimeException(
'The WWWAuthenticate multiple header implementation can only'
. ' accept an array of WWWAuthenticate headers'

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\Header;

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http;
@@ -20,60 +18,60 @@ class HeaderLoader extends PluginClassLoader
* @var array Pre-aliased Header plugins
*/
protected $plugins = [
'accept' => 'Zend\Http\Header\Accept',
'acceptcharset' => 'Zend\Http\Header\AcceptCharset',
'acceptencoding' => 'Zend\Http\Header\AcceptEncoding',
'acceptlanguage' => 'Zend\Http\Header\AcceptLanguage',
'acceptranges' => 'Zend\Http\Header\AcceptRanges',
'age' => 'Zend\Http\Header\Age',
'allow' => 'Zend\Http\Header\Allow',
'authenticationinfo' => 'Zend\Http\Header\AuthenticationInfo',
'authorization' => 'Zend\Http\Header\Authorization',
'cachecontrol' => 'Zend\Http\Header\CacheControl',
'connection' => 'Zend\Http\Header\Connection',
'contentdisposition' => 'Zend\Http\Header\ContentDisposition',
'contentencoding' => 'Zend\Http\Header\ContentEncoding',
'contentlanguage' => 'Zend\Http\Header\ContentLanguage',
'contentlength' => 'Zend\Http\Header\ContentLength',
'contentlocation' => 'Zend\Http\Header\ContentLocation',
'contentmd5' => 'Zend\Http\Header\ContentMD5',
'contentrange' => 'Zend\Http\Header\ContentRange',
'contenttransferencoding' => 'Zend\Http\Header\ContentTransferEncoding',
'contenttype' => 'Zend\Http\Header\ContentType',
'cookie' => 'Zend\Http\Header\Cookie',
'date' => 'Zend\Http\Header\Date',
'etag' => 'Zend\Http\Header\Etag',
'expect' => 'Zend\Http\Header\Expect',
'expires' => 'Zend\Http\Header\Expires',
'from' => 'Zend\Http\Header\From',
'host' => 'Zend\Http\Header\Host',
'ifmatch' => 'Zend\Http\Header\IfMatch',
'ifmodifiedsince' => 'Zend\Http\Header\IfModifiedSince',
'ifnonematch' => 'Zend\Http\Header\IfNoneMatch',
'ifrange' => 'Zend\Http\Header\IfRange',
'ifunmodifiedsince' => 'Zend\Http\Header\IfUnmodifiedSince',
'keepalive' => 'Zend\Http\Header\KeepAlive',
'lastmodified' => 'Zend\Http\Header\LastModified',
'location' => 'Zend\Http\Header\Location',
'maxforwards' => 'Zend\Http\Header\MaxForwards',
'origin' => 'Zend\Http\Header\Origin',
'pragma' => 'Zend\Http\Header\Pragma',
'proxyauthenticate' => 'Zend\Http\Header\ProxyAuthenticate',
'proxyauthorization' => 'Zend\Http\Header\ProxyAuthorization',
'range' => 'Zend\Http\Header\Range',
'referer' => 'Zend\Http\Header\Referer',
'refresh' => 'Zend\Http\Header\Refresh',
'retryafter' => 'Zend\Http\Header\RetryAfter',
'server' => 'Zend\Http\Header\Server',
'setcookie' => 'Zend\Http\Header\SetCookie',
'te' => 'Zend\Http\Header\TE',
'trailer' => 'Zend\Http\Header\Trailer',
'transferencoding' => 'Zend\Http\Header\TransferEncoding',
'upgrade' => 'Zend\Http\Header\Upgrade',
'useragent' => 'Zend\Http\Header\UserAgent',
'vary' => 'Zend\Http\Header\Vary',
'via' => 'Zend\Http\Header\Via',
'warning' => 'Zend\Http\Header\Warning',
'wwwauthenticate' => 'Zend\Http\Header\WWWAuthenticate'
'accept' => Header\Accept::class,
'acceptcharset' => Header\AcceptCharset::class,
'acceptencoding' => Header\AcceptEncoding::class,
'acceptlanguage' => Header\AcceptLanguage::class,
'acceptranges' => Header\AcceptRanges::class,
'age' => Header\Age::class,
'allow' => Header\Allow::class,
'authenticationinfo' => Header\AuthenticationInfo::class,
'authorization' => Header\Authorization::class,
'cachecontrol' => Header\CacheControl::class,
'connection' => Header\Connection::class,
'contentdisposition' => Header\ContentDisposition::class,
'contentencoding' => Header\ContentEncoding::class,
'contentlanguage' => Header\ContentLanguage::class,
'contentlength' => Header\ContentLength::class,
'contentlocation' => Header\ContentLocation::class,
'contentmd5' => Header\ContentMD5::class,
'contentrange' => Header\ContentRange::class,
'contenttransferencoding' => Header\ContentTransferEncoding::class,
'contenttype' => Header\ContentType::class,
'cookie' => Header\Cookie::class,
'date' => Header\Date::class,
'etag' => Header\Etag::class,
'expect' => Header\Expect::class,
'expires' => Header\Expires::class,
'from' => Header\From::class,
'host' => Header\Host::class,
'ifmatch' => Header\IfMatch::class,
'ifmodifiedsince' => Header\IfModifiedSince::class,
'ifnonematch' => Header\IfNoneMatch::class,
'ifrange' => Header\IfRange::class,
'ifunmodifiedsince' => Header\IfUnmodifiedSince::class,
'keepalive' => Header\KeepAlive::class,
'lastmodified' => Header\LastModified::class,
'location' => Header\Location::class,
'maxforwards' => Header\MaxForwards::class,
'origin' => Header\Origin::class,
'pragma' => Header\Pragma::class,
'proxyauthenticate' => Header\ProxyAuthenticate::class,
'proxyauthorization' => Header\ProxyAuthorization::class,
'range' => Header\Range::class,
'referer' => Header\Referer::class,
'refresh' => Header\Refresh::class,
'retryafter' => Header\RetryAfter::class,
'server' => Header\Server::class,
'setcookie' => Header\SetCookie::class,
'te' => Header\TE::class,
'trailer' => Header\Trailer::class,
'transferencoding' => Header\TransferEncoding::class,
'upgrade' => Header\Upgrade::class,
'useragent' => Header\UserAgent::class,
'vary' => Header\Vary::class,
'via' => Header\Via::class,
'warning' => Header\Warning::class,
'wwwauthenticate' => Header\WWWAuthenticate::class,
];
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http;
@@ -13,6 +11,8 @@ use ArrayIterator;
use Countable;
use Iterator;
use Traversable;
use Zend\Http\Header\Exception;
use Zend\Http\Header\GenericHeader;
use Zend\Loader\PluginClassLocator;
/**
@@ -26,7 +26,7 @@ class Headers implements Countable, Iterator
/**
* @var PluginClassLocator
*/
protected $pluginClassLoader = null;
protected $pluginClassLoader;
/**
* @var array key names for $headers array
@@ -81,7 +81,7 @@ class Headers implements Countable, Iterator
}
$current = [
'name' => $matches['name'],
'line' => trim($line)
'line' => trim($line),
];
continue;
@@ -142,7 +142,7 @@ class Headers implements Countable, Iterator
*/
public function addHeaders($headers)
{
if (!is_array($headers) && !$headers instanceof Traversable) {
if (! is_array($headers) && ! $headers instanceof Traversable) {
throw new Exception\InvalidArgumentException(sprintf(
'Expected array or Traversable; received "%s"',
(is_object($headers) ? get_class($headers) : gettype($headers))
@@ -213,8 +213,27 @@ class Headers implements Countable, Iterator
*/
public function addHeader(Header\HeaderInterface $header)
{
$this->headersKeys[] = static::createKey($header->getFieldName());
$this->headers[] = $header;
$key = static::createKey($header->getFieldName());
$index = array_search($key, $this->headersKeys);
// No header by that key presently; append key and header to list.
if ($index === false) {
$this->headersKeys[] = $key;
$this->headers[] = $header;
return $this;
}
// Header exists, and is a multi-value header; append key and header to
// list (as multi-value headers are aggregated on retrieval)
$class = ($this->getPluginClassLoader()->load(str_replace('-', '', $key))) ?: Header\GenericHeader::class;
if (in_array(Header\MultipleHeaderInterface::class, class_implements($class, true))) {
$this->headersKeys[] = $key;
$this->headers[] = $header;
return $this;
}
// Otherwise, we replace the current instance.
$this->headers[$index] = $header;
return $this;
}
@@ -259,11 +278,11 @@ class Headers implements Countable, Iterator
public function get($name)
{
$key = static::createKey($name);
if (!in_array($key, $this->headersKeys)) {
if (! $this->has($name)) {
return false;
}
$class = ($this->getPluginClassLoader()->load($key)) ?: 'Zend\Http\Header\GenericHeader';
$class = ($this->getPluginClassLoader()->load(str_replace('-', '', $key))) ?: 'Zend\Http\Header\GenericHeader';
if (in_array('Zend\Http\Header\MultipleHeaderInterface', class_implements($class, true))) {
$headers = [];
@@ -286,6 +305,7 @@ class Headers implements Countable, Iterator
if (is_array($this->headers[$index])) {
return $this->lazyLoadHeader($index);
}
return $this->headers[$index];
}
@@ -297,7 +317,7 @@ class Headers implements Countable, Iterator
*/
public function has($name)
{
return (in_array(static::createKey($name), $this->headersKeys));
return in_array(static::createKey($name), $this->headersKeys);
}
/**
@@ -403,7 +423,7 @@ class Headers implements Countable, Iterator
foreach ($this->headers as $header) {
if ($header instanceof Header\MultipleHeaderInterface) {
$name = $header->getFieldName();
if (!isset($headers[$name])) {
if (! isset($headers[$name])) {
$headers[$name] = [];
}
$headers[$name][] = $header->getFieldValue();
@@ -435,17 +455,25 @@ class Headers implements Countable, Iterator
/**
* @param $index
* @param bool $isGeneric
* @return mixed|void
*/
protected function lazyLoadHeader($index)
protected function lazyLoadHeader($index, $isGeneric = false)
{
$current = $this->headers[$index];
$key = $this->headersKeys[$index];
/* @var $class Header\HeaderInterface */
$class = ($this->getPluginClassLoader()->load($key)) ?: 'Zend\Http\Header\GenericHeader';
$class = $this->getPluginClassLoader()->load(str_replace('-', '', $key));
if ($isGeneric || ! $class) {
$class = GenericHeader::class;
}
$headers = $class::fromString($current['line']);
try {
$headers = $class::fromString($current['line']);
} catch (Exception\InvalidArgumentException $exception) {
return $this->lazyLoadHeader($index, true);
}
if (is_array($headers)) {
$this->headers[$index] = $current = array_shift($headers);
foreach ($headers as $header) {
@@ -467,6 +495,6 @@ class Headers implements Countable, Iterator
*/
protected static function createKey($name)
{
return str_replace(['-', '_', ' ', '.'], '', strtolower($name));
return str_replace(['_', ' ', '.'], '-', strtolower($name));
}
}

View File

@@ -1,10 +1,8 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @see https://github.com/zendframework/zend-http for the canonical source repository
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Http\PhpEnvironment;
@@ -40,7 +38,6 @@ class RemoteAddress
*/
protected $proxyHeader = 'HTTP_X_FORWARDED_FOR';
/**
* Changes proxy handling setting.
*
@@ -118,14 +115,14 @@ class RemoteAddress
*/
protected function getIpAddressFromProxy()
{
if (!$this->useProxy
|| (isset($_SERVER['REMOTE_ADDR']) && !in_array($_SERVER['REMOTE_ADDR'], $this->trustedProxies))
if (! $this->useProxy
|| (isset($_SERVER['REMOTE_ADDR']) && ! in_array($_SERVER['REMOTE_ADDR'], $this->trustedProxies))
) {
return false;
}
$header = $this->proxyHeader;
if (!isset($_SERVER[$header]) || empty($_SERVER[$header])) {
if (! isset($_SERVER[$header]) || empty($_SERVER[$header])) {
return false;
}

Some files were not shown because too many files have changed in this diff Show More