update 1.0.8.0

Commits for version update
This commit is contained in:
Manish Verma
2016-10-17 12:02:27 +05:30
parent dec927987b
commit 76e85db070
9674 changed files with 495757 additions and 58922 deletions

View File

@@ -104,7 +104,7 @@ class Client implements ClientInterface
return $this->sendAsync($request, $options)->wait();
}
public function requestAsync($method, $uri = null, array $options = [])
public function requestAsync($method, $uri = '', array $options = [])
{
$options = $this->prepareDefaults($options);
// Remove request modifying parameter because it can be done up-front.
@@ -123,7 +123,7 @@ class Client implements ClientInterface
return $this->transfer($request, $options);
}
public function request($method, $uri = null, array $options = [])
public function request($method, $uri = '', array $options = [])
{
$options[RequestOptions::SYNCHRONOUS] = true;
return $this->requestAsync($method, $uri, $options)->wait();
@@ -138,11 +138,14 @@ class Client implements ClientInterface
private function buildUri($uri, array $config)
{
if (!isset($config['base_uri'])) {
return $uri instanceof UriInterface ? $uri : new Psr7\Uri($uri);
// for BC we accept null which would otherwise fail in uri_for
$uri = Psr7\uri_for($uri === null ? '' : $uri);
if (isset($config['base_uri'])) {
$uri = Psr7\Uri::resolve(Psr7\uri_for($config['base_uri']), $uri);
}
return Psr7\Uri::resolve(Psr7\uri_for($config['base_uri']), $uri);
return $uri->getScheme() === '' ? $uri->withScheme('http') : $uri;
}
/**
@@ -160,9 +163,13 @@ class Client implements ClientInterface
'cookies' => false
];
// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set
if ($proxy = getenv('HTTP_PROXY')) {
$defaults['proxy']['http'] = $proxy;
// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.
// We can only trust the HTTP_PROXY environment variable in a CLI
// process due to the fact that PHP has no reliable mechanism to
// get environment variables that start with "HTTP_".
if (php_sapi_name() == 'cli' && getenv('HTTP_PROXY')) {
$defaults['proxy']['http'] = getenv('HTTP_PROXY');
}
if ($proxy = getenv('HTTPS_PROXY')) {
@@ -255,7 +262,7 @@ class Client implements ClientInterface
unset($options['save_to']);
}
// exceptions -> http_error
// exceptions -> http_errors
if (isset($options['exceptions'])) {
$options['http_errors'] = $options['exceptions'];
unset($options['exceptions']);
@@ -297,9 +304,14 @@ class Client implements ClientInterface
}
if (isset($options['multipart'])) {
$elements = $options['multipart'];
$options['body'] = new Psr7\MultipartStream($options['multipart']);
unset($options['multipart']);
$options['body'] = new Psr7\MultipartStream($elements);
}
if (isset($options['json'])) {
$options['body'] = \GuzzleHttp\json_encode($options['json']);
unset($options['json']);
$options['_conditional']['Content-Type'] = 'application/json';
}
if (!empty($options['decode_content'])
@@ -325,13 +337,10 @@ class Client implements ClientInterface
unset($options['body']);
}
if (!empty($options['auth'])) {
if (!empty($options['auth']) && is_array($options['auth'])) {
$value = $options['auth'];
$type = is_array($value)
? (isset($value[2]) ? strtolower($value[2]) : 'basic')
: $value;
$config['auth'] = $value;
switch (strtolower($type)) {
$type = isset($value[2]) ? strtolower($value[2]) : 'basic';
switch ($type) {
case 'basic':
$modify['set_headers']['Authorization'] = 'Basic '
. base64_encode("$value[0]:$value[1]");
@@ -356,11 +365,12 @@ class Client implements ClientInterface
unset($options['query']);
}
if (isset($options['json'])) {
$jsonStr = \GuzzleHttp\json_encode($options['json']);
$modify['body'] = Psr7\stream_for($jsonStr);
$options['_conditional']['Content-Type'] = 'application/json';
unset($options['json']);
// Ensure that sink is not an invalid value.
if (isset($options['sink'])) {
// TODO: Add more sink validation?
if (is_bool($options['sink'])) {
throw new \InvalidArgumentException('sink must not be a boolean');
}
}
$request = Psr7\modify_request($request, $modify);

View File

@@ -12,7 +12,7 @@ use Psr\Http\Message\UriInterface;
*/
interface ClientInterface
{
const VERSION = '6.2.0';
const VERSION = '6.2.1';
/**
* Send an HTTP request.
@@ -44,14 +44,14 @@ interface ClientInterface
* relative path to append to the base path of the client. The URL can
* contain the query string as well.
*
* @param string $method HTTP method.
* @param string|UriInterface|null $uri URI object or string (default null).
* @param array $options Request options to apply.
* @param string $method HTTP method.
* @param string|UriInterface $uri URI object or string.
* @param array $options Request options to apply.
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function request($method, $uri = null, array $options = []);
public function request($method, $uri, array $options = []);
/**
* Create and send an asynchronous HTTP request.

View File

@@ -233,7 +233,7 @@ class CookieJar implements CookieJarInterface
if ($cookie->matchesPath($path) &&
$cookie->matchesDomain($host) &&
!$cookie->isExpired() &&
(!$cookie->getSecure() || $scheme == 'https')
(!$cookie->getSecure() || $scheme === 'https')
) {
$values[] = $cookie->getName() . '='
. $cookie->getValue();

View File

@@ -56,11 +56,10 @@ class SessionCookieJar extends CookieJar
*/
protected function load()
{
$cookieJar = isset($_SESSION[$this->sessionKey])
? $_SESSION[$this->sessionKey]
: null;
$data = json_decode($cookieJar, true);
if (!isset($_SESSION[$this->sessionKey])) {
return;
}
$data = json_decode($_SESSION[$this->sessionKey], true);
if (is_array($data)) {
foreach ($data as $cookie) {
$this->setCookie(new SetCookie($cookie));

View File

@@ -86,8 +86,8 @@ class SetCookie
{
$str = $this->data['Name'] . '=' . $this->data['Value'] . '; ';
foreach ($this->data as $k => $v) {
if ($k != 'Name' && $k != 'Value' && $v !== null && $v !== false) {
if ($k == 'Expires') {
if ($k !== 'Name' && $k !== 'Value' && $v !== null && $v !== false) {
if ($k === 'Expires') {
$str .= 'Expires=' . gmdate('D, d M Y H:i:s \G\M\T', $v) . '; ';
} else {
$str .= ($v === true ? $k : "{$k}={$v}") . '; ';
@@ -307,7 +307,7 @@ class SetCookie
$cookiePath = $this->getPath();
// Match on exact matches or when path is the default empty "/"
if ($cookiePath == '/' || $cookiePath == $requestPath) {
if ($cookiePath === '/' || $cookiePath == $requestPath) {
return true;
}
@@ -317,12 +317,12 @@ class SetCookie
}
// Match if the last character of the cookie-path is "/"
if (substr($cookiePath, -1, 1) == '/') {
if (substr($cookiePath, -1, 1) === '/') {
return true;
}
// Match if the first character not included in cookie path is "/"
return substr($requestPath, strlen($cookiePath), 1) == '/';
return substr($requestPath, strlen($cookiePath), 1) === '/';
}
/**

View File

@@ -77,11 +77,11 @@ class RequestException extends TransferException
);
}
$level = floor($response->getStatusCode() / 100);
if ($level == '4') {
$level = (int) floor($response->getStatusCode() / 100);
if ($level === 4) {
$label = 'Client error';
$className = __NAMESPACE__ . '\\ClientException';
} elseif ($level == '5') {
} elseif ($level === 5) {
$label = 'Server error';
$className = __NAMESPACE__ . '\\ServerException';
} else {

View File

@@ -194,7 +194,7 @@ class CurlFactory implements CurlFactoryInterface
$conf = [
'_headers' => $easy->request->getHeaders(),
CURLOPT_CUSTOMREQUEST => $easy->request->getMethod(),
CURLOPT_URL => (string) $easy->request->getUri(),
CURLOPT_URL => (string) $easy->request->getUri()->withFragment(''),
CURLOPT_RETURNTRANSFER => false,
CURLOPT_HEADER => false,
CURLOPT_CONNECTTIMEOUT => 150,
@@ -495,12 +495,14 @@ class CurlFactory implements CurlFactoryInterface
private function createHeaderFn(EasyHandle $easy)
{
if (!isset($easy->options['on_headers'])) {
$onHeaders = null;
} elseif (!is_callable($easy->options['on_headers'])) {
throw new \InvalidArgumentException('on_headers must be callable');
} else {
if (isset($easy->options['on_headers'])) {
$onHeaders = $easy->options['on_headers'];
if (!is_callable($onHeaders)) {
throw new \InvalidArgumentException('on_headers must be callable');
}
} else {
$onHeaders = null;
}
return function ($ch, $h) use (
@@ -512,7 +514,7 @@ class CurlFactory implements CurlFactoryInterface
if ($value === '') {
$startingResponse = true;
$easy->createResponse();
if ($onHeaders) {
if ($onHeaders !== null) {
try {
$onHeaders($easy->response);
} catch (\Exception $e) {

View File

@@ -27,7 +27,7 @@ class MockHandler implements \Countable
* @param callable $onFulfilled Callback to invoke when the return value is fulfilled.
* @param callable $onRejected Callback to invoke when the return value is rejected.
*
* @return MockHandler
* @return HandlerStack
*/
public static function createWithMiddleware(
array $queue = null,

View File

@@ -105,7 +105,12 @@ class StreamHandler
$headers = \GuzzleHttp\headers_from_lines($hdrs);
list ($stream, $headers) = $this->checkDecode($options, $headers, $stream);
$stream = Psr7\stream_for($stream);
$sink = $this->createSink($stream, $options);
$sink = $stream;
if (strcasecmp('HEAD', $request->getMethod())) {
$sink = $this->createSink($stream, $options);
}
$response = new Psr7\Response($status, $headers, $sink, $ver, $reason);
if (isset($options['on_headers'])) {
@@ -118,8 +123,14 @@ class StreamHandler
}
}
// Do not drain when the request is a HEAD request because they have
// no body.
if ($sink !== $stream) {
$this->drain($stream, $sink);
$this->drain(
$stream,
$sink,
$response->getHeaderLine('Content-Length')
);
}
$this->invokeStats($options, $request, $startTime, $response, null);
@@ -149,7 +160,7 @@ class StreamHandler
$normalizedKeys = \GuzzleHttp\normalize_header_keys($headers);
if (isset($normalizedKeys['content-encoding'])) {
$encoding = $headers[$normalizedKeys['content-encoding']];
if ($encoding[0] == 'gzip' || $encoding[0] == 'deflate') {
if ($encoding[0] === 'gzip' || $encoding[0] === 'deflate') {
$stream = new Psr7\InflateStream(
Psr7\stream_for($stream)
);
@@ -163,7 +174,7 @@ class StreamHandler
= $headers[$normalizedKeys['content-length']];
$length = (int) $stream->getSize();
if ($length == 0) {
if ($length === 0) {
unset($headers[$normalizedKeys['content-length']]);
} else {
$headers[$normalizedKeys['content-length']] = [$length];
@@ -181,13 +192,27 @@ class StreamHandler
*
* @param StreamInterface $source
* @param StreamInterface $sink
* @param string $contentLength Header specifying the amount of
* data to read.
*
* @return StreamInterface
* @throws \RuntimeException when the sink option is invalid.
*/
private function drain(StreamInterface $source, StreamInterface $sink)
{
Psr7\copy_to_stream($source, $sink);
private function drain(
StreamInterface $source,
StreamInterface $sink,
$contentLength
) {
// If a content-length header is provided, then stop reading once
// that number of bytes has been read. This can prevent infinitely
// reading from a stream when dealing with servers that do not honor
// Connection: Close headers.
Psr7\copy_to_stream(
$source,
$sink,
strlen($contentLength) > 0 ? (int) $contentLength : -1
);
$sink->seek(0);
$source->close();
@@ -284,7 +309,7 @@ class StreamHandler
return $this->createResource(
function () use ($request, &$http_response_header, $context) {
$resource = fopen($request->getUri(), 'r', null, $context);
$resource = fopen((string) $request->getUri()->withFragment(''), 'r', null, $context);
$this->lastHeaders = $http_response_header;
return $resource;
}
@@ -346,7 +371,9 @@ class StreamHandler
private function add_timeout(RequestInterface $request, &$options, $value, &$params)
{
$options['http']['timeout'] = $value;
if ($value > 0) {
$options['http']['timeout'] = $value;
}
}
private function add_verify(RequestInterface $request, &$options, $value, &$params)
@@ -423,7 +450,7 @@ class StreamHandler
'bytes_transferred', 'bytes_max'];
$value = \GuzzleHttp\debug_resource($value);
$ident = $request->getMethod() . ' ' . $request->getUri();
$ident = $request->getMethod() . ' ' . $request->getUri()->withFragment('');
$this->addNotification(
$params,
function () use ($ident, $value, $map, $args) {

View File

@@ -15,25 +15,25 @@ class UriTemplate
private $variables;
/** @var array Hash for quick operator lookups */
private static $operatorHash = array(
'' => array('prefix' => '', 'joiner' => ',', 'query' => false),
'+' => array('prefix' => '', 'joiner' => ',', 'query' => false),
'#' => array('prefix' => '#', 'joiner' => ',', 'query' => false),
'.' => array('prefix' => '.', 'joiner' => '.', 'query' => false),
'/' => array('prefix' => '/', 'joiner' => '/', 'query' => false),
';' => array('prefix' => ';', 'joiner' => ';', 'query' => true),
'?' => array('prefix' => '?', 'joiner' => '&', 'query' => true),
'&' => array('prefix' => '&', 'joiner' => '&', 'query' => true)
);
private static $operatorHash = [
'' => ['prefix' => '', 'joiner' => ',', 'query' => false],
'+' => ['prefix' => '', 'joiner' => ',', 'query' => false],
'#' => ['prefix' => '#', 'joiner' => ',', 'query' => false],
'.' => ['prefix' => '.', 'joiner' => '.', 'query' => false],
'/' => ['prefix' => '/', 'joiner' => '/', 'query' => false],
';' => ['prefix' => ';', 'joiner' => ';', 'query' => true],
'?' => ['prefix' => '?', 'joiner' => '&', 'query' => true],
'&' => ['prefix' => '&', 'joiner' => '&', 'query' => true]
];
/** @var array Delimiters */
private static $delims = array(':', '/', '?', '#', '[', ']', '@', '!', '$',
'&', '\'', '(', ')', '*', '+', ',', ';', '=');
private static $delims = [':', '/', '?', '#', '[', ']', '@', '!', '$',
'&', '\'', '(', ')', '*', '+', ',', ';', '='];
/** @var array Percent encoded delimiters */
private static $delimsPct = array('%3A', '%2F', '%3F', '%23', '%5B', '%5D',
private static $delimsPct = ['%3A', '%2F', '%3F', '%23', '%5B', '%5D',
'%40', '%21', '%24', '%26', '%27', '%28', '%29', '%2A', '%2B', '%2C',
'%3B', '%3D');
'%3B', '%3D'];
public function expand($template, array $variables)
{
@@ -60,7 +60,7 @@ class UriTemplate
*/
private function parseExpression($expression)
{
$result = array();
$result = [];
if (isset(self::$operatorHash[$expression[0]])) {
$result['operator'] = $expression[0];
@@ -71,12 +71,12 @@ class UriTemplate
foreach (explode(',', $expression) as $value) {
$value = trim($value);
$varspec = array();
$varspec = [];
if ($colonPos = strpos($value, ':')) {
$varspec['value'] = substr($value, 0, $colonPos);
$varspec['modifier'] = ':';
$varspec['position'] = (int) substr($value, $colonPos + 1);
} elseif (substr($value, -1) == '*') {
} elseif (substr($value, -1) === '*') {
$varspec['modifier'] = '*';
$varspec['value'] = substr($value, 0, -1);
} else {
@@ -98,9 +98,9 @@ class UriTemplate
*/
private function expandMatch(array $matches)
{
static $rfc1738to3986 = array('+' => '%20', '%7e' => '~');
static $rfc1738to3986 = ['+' => '%20', '%7e' => '~'];
$replacements = array();
$replacements = [];
$parsed = self::parseExpression($matches[1]);
$prefix = self::$operatorHash[$parsed['operator']]['prefix'];
$joiner = self::$operatorHash[$parsed['operator']]['joiner'];
@@ -119,7 +119,7 @@ class UriTemplate
if (is_array($variable)) {
$isAssoc = $this->isAssoc($variable);
$kvp = array();
$kvp = [];
foreach ($variable as $key => $var) {
if ($isAssoc) {
@@ -131,14 +131,14 @@ class UriTemplate
if (!$isNestedArray) {
$var = rawurlencode($var);
if ($parsed['operator'] == '+' ||
$parsed['operator'] == '#'
if ($parsed['operator'] === '+' ||
$parsed['operator'] === '#'
) {
$var = $this->decodeReserved($var);
}
}
if ($value['modifier'] == '*') {
if ($value['modifier'] === '*') {
if ($isAssoc) {
if ($isNestedArray) {
// Nested arrays must allow for deeply nested
@@ -160,7 +160,7 @@ class UriTemplate
if (empty($variable)) {
$actuallyUseQuery = false;
} elseif ($value['modifier'] == '*') {
} elseif ($value['modifier'] === '*') {
$expanded = implode($joiner, $kvp);
if ($isAssoc) {
// Don't prepend the value name when using the explode
@@ -181,17 +181,17 @@ class UriTemplate
}
} else {
if ($value['modifier'] == ':') {
if ($value['modifier'] === ':') {
$variable = substr($variable, 0, $value['position']);
}
$expanded = rawurlencode($variable);
if ($parsed['operator'] == '+' || $parsed['operator'] == '#') {
if ($parsed['operator'] === '+' || $parsed['operator'] === '#') {
$expanded = $this->decodeReserved($expanded);
}
}
if ($actuallyUseQuery) {
if (!$expanded && $joiner != '&') {
if (!$expanded && $joiner !== '&') {
$expanded = $value['value'];
} else {
$expanded = $value['value'] . '=' . $expanded;

View File

@@ -5,7 +5,6 @@ use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Handler\CurlMultiHandler;
use GuzzleHttp\Handler\Proxy;
use GuzzleHttp\Handler\StreamHandler;
use Psr\Http\Message\StreamInterface;
/**
* Expands a URI template
@@ -310,7 +309,7 @@ function json_decode($json, $assoc = false, $depth = 512, $options = 0)
/**
* Wrapper for JSON encoding that throws when an error occurs.
*
* @param string $value The value being encoded
* @param mixed $value The value being encoded
* @param int $options JSON encode option bitmask
* @param int $depth Set the maximum depth. Must be greater than zero.
*