mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-25 10:33:18 +01:00
Cleaning up long lines
This commit is contained in:
parent
d8d8b0e930
commit
18de0b447e
@ -13,7 +13,6 @@ use GuzzleHttp\Adapter\Curl\CurlAdapter;
|
||||
use GuzzleHttp\Adapter\Transaction;
|
||||
use GuzzleHttp\Adapter\TransactionIterator;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use GuzzleHttp\Message\MessageFactory;
|
||||
use GuzzleHttp\Message\MessageFactoryInterface;
|
||||
use GuzzleHttp\Message\RequestInterface;
|
||||
@ -60,9 +59,10 @@ class Client implements ClientInterface
|
||||
* ]);
|
||||
*
|
||||
* @param array $config Client configuration settings
|
||||
* - base_url: Base URL of the client that is merged into relative URLs. Can be a string or
|
||||
* an array that contains a URI template followed by an associative array of
|
||||
* expansion variables to inject into the URI template.
|
||||
* - base_url: Base URL of the client that is merged into relative URLs.
|
||||
* Can be a string or an array that contains a URI template followed
|
||||
* by an associative array of expansion variables to inject into the
|
||||
* URI template.
|
||||
* - adapter: Adapter used to transfer requests
|
||||
* - parallel_adapter: Adapter used to transfer requests in parallel
|
||||
* - message_factory: Factory used to create request and response object
|
||||
@ -97,14 +97,16 @@ class Client implements ClientInterface
|
||||
|
||||
public function getConfig($keyOrPath = null)
|
||||
{
|
||||
return $keyOrPath === null ? $this->config->toArray() : $this->config->getPath($keyOrPath);
|
||||
return $keyOrPath === null
|
||||
? $this->config->toArray()
|
||||
: $this->config->getPath($keyOrPath);
|
||||
}
|
||||
|
||||
public function setConfig($keyOrPath, $value)
|
||||
{
|
||||
// Ensure that "defaults" is always an array
|
||||
if ($keyOrPath == 'defaults' && !is_array($value)) {
|
||||
throw new \InvalidArgumentException('The value for "defaults" must be an array');
|
||||
throw new \InvalidArgumentException('"defaults" must be an array');
|
||||
}
|
||||
|
||||
$this->config->setPath($keyOrPath, $value);
|
||||
@ -203,7 +205,7 @@ class Client implements ClientInterface
|
||||
return [
|
||||
'allow_redirects' => true,
|
||||
'exceptions' => true,
|
||||
'verify' => substr(__FILE__, 0, 7) == 'phar://' ? true : (__DIR__ . '/cacert.pem')
|
||||
'verify' => substr(__FILE__, 0, 7) == 'phar://' ? true : __DIR__ . '/cacert.pem'
|
||||
];
|
||||
}
|
||||
|
||||
@ -273,7 +275,12 @@ class Client implements ClientInterface
|
||||
if (!isset($config['base_url'])) {
|
||||
$this->baseUrl = new Url('', '');
|
||||
} elseif (is_array($config['base_url'])) {
|
||||
$this->baseUrl = Url::fromString(\GuzzleHttp\uriTemplate($config['base_url'][0], $config['base_url'][1]));
|
||||
$this->baseUrl = Url::fromString(
|
||||
\GuzzleHttp\uriTemplate(
|
||||
$config['base_url'][0],
|
||||
$config['base_url'][1]
|
||||
)
|
||||
);
|
||||
$config['base_url'] = (string) $this->baseUrl;
|
||||
} else {
|
||||
$this->baseUrl = Url::fromString($config['base_url']);
|
||||
@ -283,14 +290,19 @@ class Client implements ClientInterface
|
||||
private function configureDefaults(&$config)
|
||||
{
|
||||
if (isset($config['defaults'])) {
|
||||
$config['defaults'] = array_replace($this->getDefaultOptions(), $config['defaults']);
|
||||
$config['defaults'] = array_replace(
|
||||
$this->getDefaultOptions(),
|
||||
$config['defaults']
|
||||
);
|
||||
} else {
|
||||
$config['defaults'] = $this->getDefaultOptions();
|
||||
}
|
||||
|
||||
// Add the default user-agent header
|
||||
if (!isset($config['defaults']['headers'])) {
|
||||
$config['defaults']['headers'] = ['User-Agent' => static::getDefaultUserAgent()];
|
||||
$config['defaults']['headers'] = [
|
||||
'User-Agent' => static::getDefaultUserAgent()
|
||||
];
|
||||
} elseif (!isset(array_change_key_case($config['defaults']['headers'])['user-agent'])) {
|
||||
// Add the User-Agent header if one was not already set
|
||||
$config['defaults']['headers']['User-Agent'] = static::getDefaultUserAgent();
|
||||
|
@ -24,7 +24,7 @@ interface ClientInterface extends HasEmitterInterface
|
||||
*
|
||||
* @param string $method HTTP method
|
||||
* @param string|array|Url $url URL or URI template
|
||||
* @param array $options Array of request options to apply. {@see GuzzleHttp\Message\MessageFactoryInterface}
|
||||
* @param array $options Array of request options to apply.
|
||||
*
|
||||
* @return RequestInterface
|
||||
*/
|
||||
@ -34,10 +34,10 @@ interface ClientInterface extends HasEmitterInterface
|
||||
* Send a GET request
|
||||
*
|
||||
* @param string|array|Url $url URL or URI template
|
||||
* @param array $options Array of request options to apply. {@see GuzzleHttp\Message\MessageFactoryInterface}
|
||||
* @param array $options Array of request options to apply.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws RequestException When an error is encountered (network or HTTP errors)
|
||||
* @throws RequestException When an error is encountered
|
||||
*/
|
||||
public function get($url = null, $options = []);
|
||||
|
||||
@ -45,10 +45,10 @@ interface ClientInterface extends HasEmitterInterface
|
||||
* Send a HEAD request
|
||||
*
|
||||
* @param string|array|Url $url URL or URI template
|
||||
* @param array $options Array of request options to apply. {@see GuzzleHttp\Message\MessageFactoryInterface}
|
||||
* @param array $options Array of request options to apply.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws RequestException When an error is encountered (network or HTTP errors)
|
||||
* @throws RequestException When an error is encountered
|
||||
*/
|
||||
public function head($url = null, array $options = []);
|
||||
|
||||
@ -56,10 +56,10 @@ interface ClientInterface extends HasEmitterInterface
|
||||
* Send a DELETE request
|
||||
*
|
||||
* @param string|array|Url $url URL or URI template
|
||||
* @param array $options Array of request options to apply. {@see GuzzleHttp\Message\MessageFactoryInterface}
|
||||
* @param array $options Array of request options to apply.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws RequestException When an error is encountered (network or HTTP errors)
|
||||
* @throws RequestException When an error is encountered
|
||||
*/
|
||||
public function delete($url = null, array $options = []);
|
||||
|
||||
@ -67,10 +67,10 @@ interface ClientInterface extends HasEmitterInterface
|
||||
* Send a PUT request
|
||||
*
|
||||
* @param string|array|Url $url URL or URI template
|
||||
* @param array $options Array of request options to apply. {@see GuzzleHttp\Message\MessageFactoryInterface}
|
||||
* @param array $options Array of request options to apply.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws RequestException When an error is encountered (network or HTTP errors)
|
||||
* @throws RequestException When an error is encountered
|
||||
*/
|
||||
public function put($url = null, array $options = []);
|
||||
|
||||
@ -78,10 +78,10 @@ interface ClientInterface extends HasEmitterInterface
|
||||
* Send a PATCH request
|
||||
*
|
||||
* @param string|array|Url $url URL or URI template
|
||||
* @param array $options Array of request options to apply. {@see GuzzleHttp\Message\MessageFactoryInterface}
|
||||
* @param array $options Array of request options to apply.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws RequestException When an error is encountered (network or HTTP errors)
|
||||
* @throws RequestException When an error is encountered
|
||||
*/
|
||||
public function patch($url = null, array $options = []);
|
||||
|
||||
@ -89,10 +89,10 @@ interface ClientInterface extends HasEmitterInterface
|
||||
* Send an OPTIONS request
|
||||
*
|
||||
* @param string|array|Url $url URL or URI template
|
||||
* @param array $options Array of request options to apply. {@see GuzzleHttp\Message\MessageFactoryInterface}
|
||||
* @param array $options Array of request options to apply.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws RequestException When an error is encountered (network or HTTP errors)
|
||||
* @throws RequestException When an error is encountered
|
||||
*/
|
||||
public function options($url = null, array $options = []);
|
||||
|
||||
@ -103,7 +103,7 @@ interface ClientInterface extends HasEmitterInterface
|
||||
*
|
||||
* @return \GuzzleHttp\Message\ResponseInterface
|
||||
* @throws \LogicException When the adapter does not populate a response
|
||||
* @throws RequestException When an error is encountered (network or HTTP errors)
|
||||
* @throws RequestException When an error is encountered
|
||||
*/
|
||||
public function send(RequestInterface $request);
|
||||
|
||||
|
@ -5,7 +5,11 @@ namespace GuzzleHttp;
|
||||
/**
|
||||
* Key value pair collection object
|
||||
*/
|
||||
class Collection implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInterface
|
||||
class Collection implements
|
||||
\ArrayAccess,
|
||||
\IteratorAggregate,
|
||||
\Countable,
|
||||
ToArrayInterface
|
||||
{
|
||||
use PathTrait;
|
||||
|
||||
@ -147,7 +151,8 @@ class Collection implements \ArrayAccess, \IteratorAggregate, \Countable, ToArra
|
||||
*
|
||||
* @param string $value Value to search for
|
||||
*
|
||||
* @return mixed Returns the key if the value was found FALSE if the value was not found.
|
||||
* @return mixed Returns the key if the value was found FALSE if the value
|
||||
* was not found.
|
||||
*/
|
||||
public function hasValue($value)
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ abstract class AbstractRequestEvent extends AbstractEvent
|
||||
private $transaction;
|
||||
|
||||
/**
|
||||
* @param TransactionInterface $transaction Transaction that contains the request
|
||||
* @param TransactionInterface $transaction
|
||||
*/
|
||||
public function __construct(TransactionInterface $transaction)
|
||||
{
|
||||
|
@ -24,8 +24,10 @@ use GuzzleHttp\Message\ResponseInterface;
|
||||
* - total_time: Total transaction time in seconds for last transfer
|
||||
* - namelookup_time: Time in seconds until name resolving was complete
|
||||
* - connect_time: Time in seconds it took to establish the connection
|
||||
* - pretransfer_time: Time in seconds from start until just before file transfer begins
|
||||
* - starttransfer_time: Time in seconds until the first byte is about to be transferred
|
||||
* - pretransfer_time: Time in seconds from start until just before file
|
||||
* transfer begins.
|
||||
* - starttransfer_time: Time in seconds until the first byte is about to be
|
||||
* transferred.
|
||||
* - speed_download: Average download speed
|
||||
* - speed_upload: Average upload speed
|
||||
*/
|
||||
@ -34,11 +36,13 @@ abstract class AbstractTransferEvent extends AbstractRequestEvent
|
||||
private $transferInfo;
|
||||
|
||||
/**
|
||||
* @param TransactionInterface $transaction Transaction that contains the request
|
||||
* @param TransactionInterface $transaction Transaction
|
||||
* @param array $transferInfo Transfer statistics
|
||||
*/
|
||||
public function __construct(TransactionInterface $transaction, $transferInfo = [])
|
||||
{
|
||||
public function __construct(
|
||||
TransactionInterface $transaction,
|
||||
$transferInfo = []
|
||||
) {
|
||||
parent::__construct($transaction);
|
||||
$this->transferInfo = $transferInfo;
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ namespace GuzzleHttp\Event;
|
||||
/**
|
||||
* Guzzle event emitter.
|
||||
*
|
||||
* Some of this class is based on the Symfony EventDispatcher component, which ships with the following license:
|
||||
* Some of this class is based on the Symfony EventDispatcher component, which
|
||||
* ships with the following license:
|
||||
*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
@ -32,7 +33,10 @@ class Emitter implements EmitterInterface
|
||||
|
||||
public function once($eventName, callable $listener, $priority = 0)
|
||||
{
|
||||
$onceListener = function (EventInterface $event, $eventName) use (&$onceListener, $eventName, $listener, $priority) {
|
||||
$onceListener = function (
|
||||
EventInterface $event,
|
||||
$eventName
|
||||
) use (&$onceListener, $eventName, $listener, $priority) {
|
||||
$this->removeListener($eventName, $onceListener);
|
||||
$listener($event, $eventName, $this);
|
||||
};
|
||||
@ -48,7 +52,10 @@ class Emitter implements EmitterInterface
|
||||
|
||||
foreach ($this->listeners[$eventName] as $priority => $listeners) {
|
||||
if (false !== ($key = array_search($listener, $listeners, true))) {
|
||||
unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]);
|
||||
unset(
|
||||
$this->listeners[$eventName][$priority][$key],
|
||||
$this->sorted[$eventName]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,16 +12,19 @@ interface EmitterInterface
|
||||
*
|
||||
* @param string $eventName Name of the event to bind to.
|
||||
* @param callable $listener Listener to invoke when triggered.
|
||||
* @param int $priority The higher this value, the earlier an event listener will be triggered in the chain (defaults to 0)
|
||||
* @param int $priority The higher this value, the earlier an event
|
||||
* listener will be triggered in the chain (defaults to 0)
|
||||
*/
|
||||
public function on($eventName, callable $listener, $priority = 0);
|
||||
|
||||
/**
|
||||
* Binds a listener to a specific event. After the listener is triggered once, it is removed as a listener.
|
||||
* Binds a listener to a specific event. After the listener is triggered
|
||||
* once, it is removed as a listener.
|
||||
*
|
||||
* @param string $eventName Name of the event to bind to.
|
||||
* @param callable $listener Listener to invoke when triggered.
|
||||
* @param int $priority The higher this value, the earlier an event listener will be triggered in the chain (defaults to 0)
|
||||
* @param int $priority The higher this value, the earlier an event
|
||||
* listener will be triggered in the chain (defaults to 0)
|
||||
*/
|
||||
public function once($eventName, callable $listener, $priority = 0);
|
||||
|
||||
@ -34,13 +37,17 @@ interface EmitterInterface
|
||||
public function removeListener($eventName, callable $listener);
|
||||
|
||||
/**
|
||||
* Gets the listeners of a specific event or all listeners if no event is specified.
|
||||
* Gets the listeners of a specific event or all listeners if no event is
|
||||
* specified.
|
||||
*
|
||||
* @param string $eventName The name of the event. Pass null (the default) to retrieve all listeners.
|
||||
* @param string $eventName The name of the event. Pass null (the default)
|
||||
* to retrieve all listeners.
|
||||
*
|
||||
* @return array The event listeners for the specified event, or all event listeners by event name.
|
||||
* The format of the array when retrieving a specific event list is an array of callables.
|
||||
* The format of the array when retrieving all listeners is an associative array of arrays of callables.
|
||||
* @return array The event listeners for the specified event, or all event
|
||||
* listeners by event name. The format of the array when retrieving a
|
||||
* specific event list is an array of callables. The format of the array
|
||||
* when retrieving all listeners is an associative array of arrays of
|
||||
* callables.
|
||||
*/
|
||||
public function listeners($eventName = null);
|
||||
|
||||
|
@ -7,9 +7,11 @@ use GuzzleHttp\Message\ResponseInterface;
|
||||
use GuzzleHttp\Adapter\TransactionInterface;
|
||||
|
||||
/**
|
||||
* Event object emitted after a request has been sent and an error was encountered
|
||||
* Event object emitted after a request has been sent and an error was
|
||||
* encountered.
|
||||
*
|
||||
* You may intercept the exception and inject a response into the event to rescue the request.
|
||||
* You may intercept the exception and inject a response into the event to
|
||||
* rescue the request.
|
||||
*/
|
||||
class ErrorEvent extends AbstractTransferEvent
|
||||
{
|
||||
@ -20,8 +22,11 @@ class ErrorEvent extends AbstractTransferEvent
|
||||
* @param RequestException $e Exception encountered
|
||||
* @param array $transferStats Array of transfer statistics
|
||||
*/
|
||||
public function __construct(TransactionInterface $transaction, RequestException $e, $transferStats = [])
|
||||
{
|
||||
public function __construct(
|
||||
TransactionInterface $transaction,
|
||||
RequestException $e,
|
||||
$transferStats = []
|
||||
) {
|
||||
parent::__construct($transaction, $transferStats);
|
||||
$this->exception = $e;
|
||||
}
|
||||
|
@ -54,9 +54,10 @@ final class RequestEvents
|
||||
TransactionInterface $transaction,
|
||||
array $stats = []
|
||||
) {
|
||||
$transaction->getResponse()->setEffectiveUrl($transaction->getRequest()->getUrl());
|
||||
$request = $transaction->getRequest();
|
||||
$transaction->getResponse()->setEffectiveUrl($request->getUrl());
|
||||
try {
|
||||
$transaction->getRequest()->getEmitter()->emit(
|
||||
$request->getEmitter()->emit(
|
||||
'complete',
|
||||
new CompleteEvent($transaction, $stats)
|
||||
);
|
||||
|
@ -3,7 +3,8 @@
|
||||
namespace GuzzleHttp;
|
||||
|
||||
/**
|
||||
* Trait implementing ToArrayInterface, \ArrayAccess, \Countable, and \IteratorAggregate
|
||||
* Trait implementing ToArrayInterface, \ArrayAccess, \Countable, and
|
||||
* \IteratorAggregate.
|
||||
*/
|
||||
trait HasDataTrait
|
||||
{
|
||||
|
@ -33,7 +33,8 @@ trait HasHeadersTrait
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid header value provided: ' . var_export($value, true));
|
||||
throw new \InvalidArgumentException('Invalid header value '
|
||||
. 'provided: ' . var_export($value, true));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -80,7 +81,8 @@ trait HasHeadersTrait
|
||||
$this->headers[$name] = $value;
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid header value provided: ' . var_export($value, true));
|
||||
throw new \InvalidArgumentException('Invalid header value '
|
||||
. 'provided: ' . var_export($value, true));
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -10,65 +10,96 @@ use GuzzleHttp\Url;
|
||||
interface MessageFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Create a new request based on the HTTP method
|
||||
* Create a new request based on the HTTP method.
|
||||
*
|
||||
* @param string $method HTTP method (GET, POST, PUT, PATCH, HEAD, DELETE, ...)
|
||||
* @param string|Url $url HTTP URL to connect to
|
||||
* @param array $options Array of options to apply to the request
|
||||
* - "headers": Associative array of headers to add to the request.
|
||||
* - "body": string|resource|array|StreamInterface that represents the body to send over the wire.
|
||||
* - "query": Associative array of query string values to add to the request.
|
||||
* - "auth": Array of HTTP authentication parameters to use with the request. The array must contain the
|
||||
* username in index [0], the password in index [1], and can optionally contain the authentication type
|
||||
* in index [2]. The authentication types are: "Basic", "Digest", "NTLM", (defaults to "Basic").
|
||||
* The selected authentication type must be supported by the adapter used by a client.
|
||||
* - "version": The HTTP protocol version to use with the request. Defaults to 1.1.
|
||||
* - "cookies": Pass an associative array containing cookies to send in the request and start a new cookie
|
||||
* session, set to a {@see GuzzleHttp\Cookie\CookieJarInterface} object to us an existing
|
||||
* cookie jar, or set to ``true`` to use a shared cookie session associated with the client.
|
||||
* - "allow_redirects": Set to false to disable redirects. Set to true to enable normal redirects with a maximum
|
||||
* number of 5 redirects. Pass an associative array containing the 'max' key to specify the maximum number of
|
||||
* redirects and optionally provide a 'strict' key value to specify whether or not to use strict RFC
|
||||
* compliant redirects (meaning redirect POST requests with POST requests vs. doing what most browsers do
|
||||
* which is redirect POST requests with GET requests).
|
||||
* - "save_to": Specify where the body of a response will be saved. Pass a string to specify the path to a file
|
||||
* that will store the contents of the response body. Pass a resource returned from fopen to write the
|
||||
* response to a PHP stream. Pass a {@see GuzzleHttp\Stream\StreamInterface} object to stream the response body
|
||||
* to an open Guzzle stream.
|
||||
* - "events": Associative array mapping event names to a callable or an associative array containing the 'fn'
|
||||
* key that maps to a callable, an optional 'priority' key used to specify the event priority, and an optional
|
||||
* 'once' key used to specify if the event should remove itself the first time it is triggered.
|
||||
* - "subscribers": Array of event subscribers to add to the request. Each value in the array must be an
|
||||
* instance of {@see GuzzleHttp\Event\SubscriberInterface}.
|
||||
* - "exceptions": Set to false to disable throwing exceptions on an HTTP protocol error (e.g. 404, 500, etc).
|
||||
* Exceptions are thrown by default when HTTP protocol errors are encountered.
|
||||
* - "timeout": Float describing the timeout of the request in seconds. Use 0 to wait indefinitely.
|
||||
* - "connect_timeout": Float describing the number of seconds to wait while trying to connect. Use 0 to wait
|
||||
* indefinitely. This setting must be supported by the adapter used to send a request.
|
||||
* - "verify": Set to true to enable SSL cert validation (the default), false to disable validation, or supply
|
||||
* the path to a CA bundle to enable verification using a custom certificate.
|
||||
* - "cert": Set to a string to specify the path to a file containing a PEM formatted certificate. If a password
|
||||
* is required, then set an array containing the path to the PEM file followed by the the password required
|
||||
* for the certificate.
|
||||
* - "ssl_key": Specify the path to a file containing a private SSL key in PEM format. If a password is
|
||||
* required, then set an array containing the path to the SSL key followed by the password required for the
|
||||
* certificate.
|
||||
* - "proxy": Specify an HTTP proxy (e.g. "http://username:password@192.168.16.1:10")
|
||||
* - "debug": Set to true or a PHP fopen stream resource to enable debug output with the adapter used to send a
|
||||
* request. For example, when using cURL to transfer requests, cURL's verbose output will be emitted. When
|
||||
* using the PHP stream wrapper, stream wrapper notifications will be emitted. If set to true, the output is
|
||||
* written to PHP's STDOUT.
|
||||
* - "stream": Set to true to stream a response rather than download it all up-front. (Note: This option might
|
||||
* not be supported by every HTTP adapter, but the interface of the response object remains the same.)
|
||||
* - "expect": Set to true to enable the "Expect: 100-Continue" header for a request that send a body. Set to
|
||||
* false to disable "Expect: 100-Continue". Set to a number so that the size of the payload must be greater
|
||||
* than the number in order to send the Expect header. Setting to a number will send the Expect header for
|
||||
* all requests in which the size of the payload cannot be determined or where the body is not rewindable.
|
||||
* - "config": Associative array of config options that are forwarded to a request's configuration collection.
|
||||
* These values are used as configuration options that can be consumed by plugins and adapters.
|
||||
* This method accepts an associative array of request options:
|
||||
*
|
||||
* - headers: Associative array of headers to add to the request.
|
||||
* - body: string|resource|array|StreamInterface that represents the body
|
||||
* to send over the wire.
|
||||
* - query: Associative array of query string values to add to the request.
|
||||
* - auth: Array of HTTP authentication parameters to use with the request.
|
||||
* The array must contain the username in index [0], the password in
|
||||
* index [1], and can optionally contain the authentication type in index
|
||||
* [2]. The authentication types are "basic" and "digest". Defaults to
|
||||
* "basic". The selected authentication type must be supported by the
|
||||
* adapter used by a client.
|
||||
* - version: The HTTP protocol version to use with the request. Defaults
|
||||
* to "1.1".
|
||||
* - cookies: Pass an associative array containing cookies to send in the
|
||||
* request and start a new cookie session, set to a
|
||||
* {@see GuzzleHttp\Cookie\CookieJarInterface} object to us an existing
|
||||
* cookie jar, or set to ``true`` to use a shared cookie session
|
||||
* associated with the client.
|
||||
* - allow_redirects: Set to false to disable redirects. Set to true to
|
||||
* enable normal redirects with a maximum number of 5 redirects. Pass an
|
||||
* associative array containing the 'max' key to specify the maximum
|
||||
* number of redirects, optionally provide a 'strict' key value to
|
||||
* specify whether or not to use strict RFC compliant redirects (meaning
|
||||
* redirect POST requests with POST requests vs. doing what most browsers
|
||||
* do which is redirect POST requests with GET requests), and optionally
|
||||
* provide a 'referer' key that can be set to true or false to specify if
|
||||
* the Referer header should be added to redirected requests.
|
||||
* - save_to: Specify where the body of a response will be saved. Pass a
|
||||
* string to specify the path to a file that will store the contents of
|
||||
* the response body. Pass a resource returned from fopen to write the
|
||||
* response to a PHP stream. Pass a
|
||||
* {@see GuzzleHttp\Stream\StreamInterface} object to stream the response
|
||||
* body to an open Guzzle stream.
|
||||
* - events: Associative array mapping event names to a callable or an
|
||||
* associative array containing the 'fn' key that maps to a callable, an
|
||||
* optional 'priority' key used to specify the event priority, and an
|
||||
* optional 'once' key used to specify if the event should remove itself
|
||||
* the first time it is triggered.
|
||||
* - subscribers: Array of event subscribers to add to the request. Each
|
||||
* value in the array must be an instance of
|
||||
* {@see GuzzleHttp\Event\SubscriberInterface}.
|
||||
* - exceptions: Set to false to disable throwing exceptions on an HTTP
|
||||
* protocol error (e.g. 404, 500, etc). Exceptions are thrown by default
|
||||
* when HTTP protocol errors are encountered.
|
||||
* - timeout: Float describing the timeout of the request in seconds. Use 0
|
||||
* to wait indefinitely.
|
||||
* - connect_timeout: Float describing the number of seconds to wait while
|
||||
* trying to connect. Use 0 to wait indefinitely. This setting must be
|
||||
* supported by the adapter used to send a request.
|
||||
* - verify: Set to true to enable SSL cert validation (the default), false
|
||||
* to disable validation, or supply the path to a CA bundle to enable
|
||||
* verification using a custom certificate.
|
||||
* - cert: Set to a string to specify the path to a file containing a PEM
|
||||
* formatted certificate. If a password is required, then set an array
|
||||
* containing the path to the PEM file followed by the the password
|
||||
* required for the certificate.
|
||||
* - ssl_key: Specify the path to a file containing a private SSL key in
|
||||
* PEM format. If a password is required, then set an array containing
|
||||
* the path to the SSL key followed by the password required for the
|
||||
* certificate.
|
||||
* - proxy: Specify an HTTP proxy (e.g.
|
||||
* "http://username:password@192.168.16.1:10")
|
||||
* - debug: Set to true or a PHP fopen stream resource to enable debug
|
||||
* output with the adapter used to send a request. For example, when
|
||||
* using cURL to transfer requests, cURL's verbose output will be emitted.
|
||||
* When using the PHP stream wrapper, stream wrapper notifications will be
|
||||
* emitted. If set to true, the output is written to PHP's STDOUT.
|
||||
* - stream: Set to true to stream a response rather than download it all
|
||||
* up-front. (Note: This option might not be supported by every HTTP
|
||||
* adapter, but the interface of the response object remains the same.)
|
||||
* - expect: Set to true to enable the "Expect: 100-Continue" header for a
|
||||
* request that send a body. Set to false to disable
|
||||
* "Expect: 100-Continue". Set to a number so that the size of the
|
||||
* payload must be greater than the number in order to send the Expect
|
||||
* header. Setting to a number will send the Expect header for all
|
||||
* requests in which the size of the payload cannot be determined or
|
||||
* where the body is not rewindable.
|
||||
* - config: Associative array of config options that are forwarded to a
|
||||
* request's configuration collection. These values are used as
|
||||
* configuration options that can be consumed by plugins and adapters.
|
||||
*
|
||||
* @param string $method HTTP method (GET, POST, PUT, etc ...)
|
||||
* @param string|Url $url HTTP URL to connect to
|
||||
* @param array $options Array of options to apply to the request
|
||||
*
|
||||
* @return RequestInterface
|
||||
* @link http://docs.guzzlephp.org/clients.html#request-options In-depth reference information about each option
|
||||
* @link http://docs.guzzlephp.org/clients.html#request-options
|
||||
*/
|
||||
public function createRequest($method, $url, array $options = []);
|
||||
|
||||
@ -81,9 +112,14 @@ interface MessageFactoryInterface
|
||||
* @param array $options Response options
|
||||
* - protocol_version: HTTP protocol version
|
||||
* - header_factory: Factory used to create headers
|
||||
* - *: Any other options used by a concrete message implementation
|
||||
* - And any other options used by a concrete message implementation
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function createResponse($statusCode, array $headers = [], $body = null, array $options = []);
|
||||
public function createResponse(
|
||||
$statusCode,
|
||||
array $headers = [],
|
||||
$body = null,
|
||||
array $options = []
|
||||
);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class Request extends AbstractMessage implements RequestInterface
|
||||
/** @var Url HTTP Url */
|
||||
private $url;
|
||||
|
||||
/** @var string HTTP method (GET, PUT, POST, DELETE, HEAD, OPTIONS, TRACE) */
|
||||
/** @var string HTTP method */
|
||||
private $method;
|
||||
|
||||
/** @var Collection Transfer options */
|
||||
@ -25,15 +25,21 @@ class Request extends AbstractMessage implements RequestInterface
|
||||
|
||||
/**
|
||||
* @param string $method HTTP method
|
||||
* @param string|Url $url HTTP URL to connect to. The URI scheme, host header, and URI are parsed from the
|
||||
* full URL. If query string parameters are present they will be parsed as well.
|
||||
* @param string|Url $url HTTP URL to connect to. The URI scheme,
|
||||
* host header, and URI are parsed from the full URL. If query string
|
||||
* parameters are present they will be parsed as well.
|
||||
* @param array|Collection $headers HTTP headers
|
||||
* @param mixed $body Body to send with the request
|
||||
* @param array $options Array of options to use with the request
|
||||
* - emitter: Event emitter to use with the request
|
||||
*/
|
||||
public function __construct($method, $url, $headers = [], $body = null, array $options = [])
|
||||
{
|
||||
public function __construct(
|
||||
$method,
|
||||
$url,
|
||||
$headers = [],
|
||||
$body = null,
|
||||
array $options = []
|
||||
) {
|
||||
$this->setUrl($url);
|
||||
$this->method = strtoupper($method);
|
||||
$this->handleOptions($options);
|
||||
@ -162,11 +168,13 @@ class Request extends AbstractMessage implements RequestInterface
|
||||
|
||||
protected function getStartLine()
|
||||
{
|
||||
return trim($this->method . ' ' . $this->getResource()) . ' HTTP/' . $this->getProtocolVersion();
|
||||
return trim($this->method . ' ' . $this->getResource())
|
||||
. ' HTTP/' . $this->getProtocolVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a subscriber that ensures a request's body is prepared before sending
|
||||
* Adds a subscriber that ensures a request's body is prepared before
|
||||
* sending.
|
||||
*/
|
||||
private function addPrepareEvent()
|
||||
{
|
||||
@ -183,7 +191,9 @@ class Request extends AbstractMessage implements RequestInterface
|
||||
$port = $this->url->getPort();
|
||||
$scheme = $this->url->getScheme();
|
||||
if ($host = $this->url->getHost()) {
|
||||
if (($port == 80 && $scheme == 'http') || ($port == 443 && $scheme == 'https')) {
|
||||
if (($port == 80 && $scheme == 'http') ||
|
||||
($port == 443 && $scheme == 'https')
|
||||
) {
|
||||
$this->setHeader('Host', $this->url->getHost());
|
||||
} else {
|
||||
$this->setHeader('Host', $this->url->getHost() . ':' . $port);
|
||||
|
@ -46,14 +46,16 @@ interface RequestInterface extends MessageInterface, HasEmitterInterface
|
||||
public function getUrl();
|
||||
|
||||
/**
|
||||
* Get the resource part of the the request, including the path, query string, and fragment
|
||||
* Get the resource part of the the request, including the path, query
|
||||
* string, and fragment.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResource();
|
||||
|
||||
/**
|
||||
* Get the collection of key value pairs that will be used as the query string in the request
|
||||
* Get the collection of key value pairs that will be used as the query
|
||||
* string in the request.
|
||||
*
|
||||
* @return Query
|
||||
*/
|
||||
@ -108,7 +110,8 @@ interface RequestInterface extends MessageInterface, HasEmitterInterface
|
||||
public function getHost();
|
||||
|
||||
/**
|
||||
* Set the host of the request. Including a port in the host will modify the port of the request.
|
||||
* Set the host of the request. Including a port in the host will modify
|
||||
* the port of the request.
|
||||
*
|
||||
* @param string $host Host to set (e.g. www.yahoo.com, www.yahoo.com:80)
|
||||
*
|
||||
|
@ -10,7 +10,7 @@ use GuzzleHttp\Stream\StreamInterface;
|
||||
*/
|
||||
class Response extends AbstractMessage implements ResponseInterface
|
||||
{
|
||||
/** @var array Array of reason phrases and their corresponding status codes */
|
||||
/** @var array Mapping of status codes to reason phrases */
|
||||
private static $statusTexts = array(
|
||||
100 => 'Continue',
|
||||
101 => 'Switching Protocols',
|
||||
@ -82,15 +82,19 @@ class Response extends AbstractMessage implements ResponseInterface
|
||||
private $effectiveUrl;
|
||||
|
||||
/**
|
||||
* @param string $statusCode The response status code (e.g. 200, 404, etc)
|
||||
* @param string $statusCode The response status code (e.g. 200)
|
||||
* @param array $headers The response headers
|
||||
* @param StreamInterface $body The body of the response
|
||||
* @param array $options Response message options
|
||||
* - reason_phrase: Set a custom reason phrase
|
||||
* - protocol_version: Set a custom protocol version
|
||||
*/
|
||||
public function __construct($statusCode, array $headers = [], StreamInterface $body = null, array $options = [])
|
||||
{
|
||||
public function __construct(
|
||||
$statusCode,
|
||||
array $headers = [],
|
||||
StreamInterface $body = null,
|
||||
array $options = []
|
||||
) {
|
||||
$this->statusCode = (string) $statusCode;
|
||||
$this->handleOptions($options);
|
||||
|
||||
|
@ -23,14 +23,16 @@ interface ResponseInterface extends MessageInterface
|
||||
public function getReasonPhrase();
|
||||
|
||||
/**
|
||||
* Get the effective URL that resulted in this response (e.g. the last redirect URL)
|
||||
* Get the effective URL that resulted in this response (e.g. the last
|
||||
* redirect URL).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEffectiveUrl();
|
||||
|
||||
/**
|
||||
* Set the effective URL that resulted in this response (e.g. the last redirect URL)
|
||||
* Set the effective URL that resulted in this response (e.g. the last
|
||||
* redirect URL).
|
||||
*
|
||||
* @param string $url Effective URL
|
||||
*
|
||||
|
@ -945,7 +945,9 @@ class Mimetypes
|
||||
{
|
||||
$extension = strtolower($extension);
|
||||
|
||||
return isset($this->mimetypes[$extension]) ? $this->mimetypes[$extension] : null;
|
||||
return isset($this->mimetypes[$extension])
|
||||
? $this->mimetypes[$extension]
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,7 +68,8 @@ trait PathTrait
|
||||
$queue = explode('/', $path);
|
||||
while (null !== ($key = array_shift($queue))) {
|
||||
if (!is_array($current)) {
|
||||
throw new \RuntimeException("Trying to setPath {$path}, but {$key} is set and is not an array");
|
||||
throw new \RuntimeException("Trying to setPath {$path}, but "
|
||||
. "{$key} is set and is not an array");
|
||||
} elseif (!$queue) {
|
||||
if ($key == '[]') {
|
||||
$current[] = $value;
|
||||
|
@ -54,7 +54,8 @@ class Query extends Collection
|
||||
}
|
||||
}
|
||||
|
||||
// Use the duplicate aggregator if duplicates were found and not using PHP style arrays
|
||||
// Use the duplicate aggregator if duplicates were found and not using
|
||||
// PHP style arrays.
|
||||
if ($foundDuplicates && !$foundPhpStyle) {
|
||||
$q->setAggregator(self::duplicateAggregator());
|
||||
}
|
||||
|
14
src/Url.php
14
src/Url.php
@ -34,7 +34,8 @@ class Url
|
||||
'user' => null, 'pass' => null, 'fragment' => null);
|
||||
|
||||
if (false === ($parts = parse_url($url))) {
|
||||
throw new \InvalidArgumentException('Unable to parse malformed url: ' . $url);
|
||||
throw new \InvalidArgumentException('Unable to parse malformed '
|
||||
. 'url: ' . $url);
|
||||
}
|
||||
|
||||
$parts += $defaults;
|
||||
@ -50,7 +51,8 @@ class Url
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a URL from parse_url parts. The generated URL will be a relative URL if a scheme or host are not provided.
|
||||
* Build a URL from parse_url parts. The generated URL will be a relative
|
||||
* URL if a scheme or host are not provided.
|
||||
*
|
||||
* @param array $parts Array of parse_url parts
|
||||
*
|
||||
@ -346,7 +348,10 @@ class Url
|
||||
*/
|
||||
public function addPath($relativePath)
|
||||
{
|
||||
if ($relativePath != '/' && is_string($relativePath) && strlen($relativePath) > 0) {
|
||||
if ($relativePath != '/' &&
|
||||
is_string($relativePath) &&
|
||||
strlen($relativePath) > 0
|
||||
) {
|
||||
// Add a leading slash if needed
|
||||
if ($relativePath[0] != '/') {
|
||||
$relativePath = '/' . $relativePath;
|
||||
@ -454,7 +459,8 @@ class Url
|
||||
} elseif (is_array($query)) {
|
||||
$this->query = new Query($query);
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Query must be a QueryInterface, array, or string');
|
||||
throw new \InvalidArgumentException('Query must be a '
|
||||
. 'QueryInterface, array, or string');
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -10,9 +10,9 @@ const VERSION = '4.0-dev';
|
||||
/**
|
||||
* Send a custom request
|
||||
*
|
||||
* @param string $method HTTP request method (GET, POST, HEAD, DELETE, PUT, etc)
|
||||
* @param string $method HTTP request method
|
||||
* @param string $url URL of the request
|
||||
* @param array $options Options to use with the request. See: GuzzleHttp\Message\RequestFactory::applyOptions()
|
||||
* @param array $options Options to use with the request.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user