Client
in package
implements
ClientInterface
Interfaces, Classes and Traits
- ClientInterface
- Client interface for sending HTTP requests.
Table of Contents
- $config : array<string|int, mixed>
- __call() : PromiseInterface
- __construct() : mixed
- Clients accept an array of constructor parameters.
- delete() :
- deleteAsync() :
- get() :
- getAsync() :
- getConfig() : mixed
- Get a client configuration option.
- head() :
- headAsync() :
- patch() :
- patchAsync() :
- post() :
- postAsync() :
- put() :
- putAsync() :
- request() : ResponseInterface
- Create and send an HTTP request.
- requestAsync() : PromiseInterface
- Create and send an asynchronous HTTP request.
- send() : ResponseInterface
- Send an HTTP request.
- sendAsync() : PromiseInterface
- Asynchronously send an HTTP request.
- applyOptions() : RequestInterface
- Applies the array of request options to a request.
- buildUri() : UriInterface
- configureDefaults() : void
- Configures the default options for a client.
- invalidBody() : void
- Throw Exception with pre-set message.
- prepareDefaults() : array<string|int, mixed>
- Merges default options into the array.
- transfer() : PromiseInterface
- Transfers the given request and applies request options.
Properties
$config
private
array<string|int, mixed>
$config
Methods
__call()
public
__call(string $method, array<string|int, mixed> $args) : PromiseInterface
Parameters
- $method : string
- $args : array<string|int, mixed>
Return values
PromiseInterface —__construct()
Clients accept an array of constructor parameters.
public
__construct([array<string|int, mixed> $config = [] ]) : mixed
Here's an example of creating a client using a base_uri and an array of default request options to apply to each request:
$client = new Client([
'base_uri' => 'http://www.foo.com/1.0/',
'timeout' => 0,
'allow_redirects' => false,
'proxy' => '192.168.16.1:10'
]);
Client configuration settings include the following options:
- handler: (callable) Function that transfers HTTP requests over the wire. The function is called with a Psr7\Http\Message\RequestInterface and array of transfer options, and must return a GuzzleHttp\Promise\PromiseInterface that is fulfilled with a Psr7\Http\Message\ResponseInterface on success. If no handler is provided, a default handler will be created that enables all of the request options below by attaching all of the default middleware to the handler.
- base_uri: (string|UriInterface) Base URI of the client that is merged into relative URIs. Can be a string or instance of UriInterface.
- **: any request option
Parameters
- $config : array<string|int, mixed> = []
-
Client configuration settings.
Tags
Return values
mixed —delete()
public
delete(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—deleteAsync()
public
deleteAsync(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—get()
public
get(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—getAsync()
public
getAsync(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—getConfig()
Get a client configuration option.
public
getConfig([string|null $option = null ]) : mixed
These options include default request options of the client, a "handler" (if utilized by the concrete client), and a "base_uri" if utilized by the concrete client.
Parameters
- $option : string|null = null
-
The config option to retrieve.
Return values
mixed —head()
public
head(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—headAsync()
public
headAsync(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—patch()
public
patch(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—patchAsync()
public
patchAsync(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—post()
public
post(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—postAsync()
public
postAsync(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—put()
public
put(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—putAsync()
public
putAsync(string|UriInterface $uri, array<string|int, mixed> $options = []) :
Parameters
- $uri : string|UriInterface
- $options = [] : array<string|int, mixed>
Return values
—request()
Create and send an HTTP request.
public
request(string $method[, string|UriInterface $uri = '' ][, array<string|int, mixed> $options = [] ]) : ResponseInterface
Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well.
Parameters
- $method : string
-
HTTP method.
- $uri : string|UriInterface = ''
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply. See \GuzzleHttp\RequestOptions.
Tags
Return values
ResponseInterface —requestAsync()
Create and send an asynchronous HTTP request.
public
requestAsync(string $method[, string|UriInterface $uri = '' ][, array<string|int, mixed> $options = [] ]) : PromiseInterface
Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well. Use an array to provide a URL template and additional variables to use in the URL template expansion.
Parameters
- $method : string
-
HTTP method
- $uri : string|UriInterface = ''
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply. See \GuzzleHttp\RequestOptions.
Return values
PromiseInterface —send()
Send an HTTP request.
public
send(RequestInterface $request[, array<string|int, mixed> $options = [] ]) : ResponseInterface
Parameters
- $request : RequestInterface
-
Request to send
- $options : array<string|int, mixed> = []
-
Request options to apply to the given request and to the transfer. See \GuzzleHttp\RequestOptions.
Tags
Return values
ResponseInterface —sendAsync()
Asynchronously send an HTTP request.
public
sendAsync(RequestInterface $request[, array<string|int, mixed> $options = [] ]) : PromiseInterface
Parameters
- $request : RequestInterface
-
Request to send
- $options : array<string|int, mixed> = []
-
Request options to apply to the given request and to the transfer. See \GuzzleHttp\RequestOptions.
Return values
PromiseInterface —applyOptions()
Applies the array of request options to a request.
private
applyOptions(RequestInterface $request, array<string|int, mixed> &$options) : RequestInterface
Parameters
- $request : RequestInterface
- $options : array<string|int, mixed>
Return values
RequestInterface —buildUri()
private
buildUri(string|null $uri, array<string|int, mixed> $config) : UriInterface
Parameters
- $uri : string|null
- $config : array<string|int, mixed>
Return values
UriInterface —configureDefaults()
Configures the default options for a client.
private
configureDefaults(array<string|int, mixed> $config) : void
Parameters
- $config : array<string|int, mixed>
Return values
void —invalidBody()
Throw Exception with pre-set message.
private
invalidBody() : void
Tags
Return values
void —prepareDefaults()
Merges default options into the array.
private
prepareDefaults(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed>
-
Options to modify by reference
Return values
array<string|int, mixed> —transfer()
Transfers the given request and applies request options.
private
transfer(RequestInterface $request, array<string|int, mixed> $options) : PromiseInterface
The URI of the request is not modified and the request options are used as-is without merging in default options.
Parameters
- $request : RequestInterface
- $options : array<string|int, mixed>
-
See \GuzzleHttp\RequestOptions.