Client
in package
implements
ClientInterface, ClientInterface
uses
ClientTrait
Tags
Table of Contents
Interfaces
- ClientInterface
- Client interface for sending HTTP requests.
- ClientInterface
Properties
- $config : array<string|int, mixed>
Methods
- __call() : PromiseInterface|ResponseInterface
- __construct() : mixed
- Clients accept an array of constructor parameters.
- delete() : ResponseInterface
- Create and send an HTTP DELETE request.
- deleteAsync() : PromiseInterface
- Create and send an asynchronous HTTP DELETE request.
- get() : ResponseInterface
- Create and send an HTTP GET request.
- getAsync() : PromiseInterface
- Create and send an asynchronous HTTP GET request.
- getConfig() : mixed
- Get a client configuration option.
- head() : ResponseInterface
- Create and send an HTTP HEAD request.
- headAsync() : PromiseInterface
- Create and send an asynchronous HTTP HEAD request.
- patch() : ResponseInterface
- Create and send an HTTP PATCH request.
- patchAsync() : PromiseInterface
- Create and send an asynchronous HTTP PATCH request.
- post() : ResponseInterface
- Create and send an HTTP POST request.
- postAsync() : PromiseInterface
- Create and send an asynchronous HTTP POST request.
- put() : ResponseInterface
- Create and send an HTTP PUT request.
- putAsync() : PromiseInterface
- Create and send an asynchronous HTTP PUT request.
- 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.
- sendRequest() : ResponseInterface
- The HttpClient PSR (PSR-18) specify this method.
- applyOptions() : RequestInterface
- Applies the array of request options to a request.
- buildUri() : UriInterface
- canStringifyDeprecatedValue() : bool
- castDeprecatedHeaderOptionValues() : array<int, string>
- configureDefaults() : void
- Configures the default options for a client.
- createBodyStream() : StreamInterface
- invalidBody() : InvalidArgumentException
- Return an InvalidArgumentException with pre-set message.
- isProtocolVersionValid() : bool
- normalizeDeprecatedAuthOptionValues() : void
- normalizeDeprecatedIntegerOptionValues() : void
- normalizeDeprecatedNumericOptionValues() : void
- normalizeDeprecatedRequestOptionValues() : array<string, mixed>
- Normalize values that guzzlehttp/guzzle 8.0 rejects only after the corresponding 7.x deprecation has already been emitted.
- normalizeDeprecatedStringOptionValues() : void
- normalizeDeprecatedTlsFileOptionValues() : void
- normalizeNonFiniteFloats() : array<string|int, mixed>
- Converts non-finite floats in the array to the strings PHP coerces them to, as implicit coercion of NAN emits a warning on PHP 8.5.
- normalizeProtocolVersion() : string
- prepareDefaults() : array<string|int, mixed>
- Merges default options into the array.
- shouldPreserveHost() : bool
- Whether to preserve an existing Host header when the URI changes.
- stringifyDeprecatedValue() : string
- stringifyScalar() : string
- transfer() : PromiseInterface
- Transfers the given request and applies request options.
- warnAboutInvalidAllowRedirectsOptionTypes() : void
- warnAboutInvalidAuthOptionTypes() : void
- warnAboutInvalidFormParamArray() : bool
- warnAboutInvalidFormParamTypes() : void
- warnAboutInvalidHeaderOptionTypes() : void
- warnAboutInvalidMultipartOptionTypes() : void
- warnAboutInvalidProtocolValues() : void
- warnAboutInvalidProxyOptionTypes() : void
- warnAboutInvalidRequestOptionTypes() : void
- warnAboutInvalidTlsFileOptionTypes() : void
- warnAboutRequestLevelHandler() : void
- warnIfPresentAndNotArray() : void
- warnIfPresentAndNotBool() : void
- warnIfPresentAndNotBoolOrInt() : void
- warnIfPresentAndNotBoolOrResource() : void
- warnIfPresentAndNotBoolOrString() : void
- warnIfPresentAndNotCallable() : void
- warnIfPresentAndNotInt() : void
- warnIfPresentAndNotNumber() : void
- warnIfPresentAndNotString() : void
- warnIfPresentAndNotStringArray() : void
- warnIfPresentAndNotStringOrNumber() : void
- warnInvalidRequestOptionType() : void
Properties
$config
private
array<string|int, mixed>
$config
Default request options
Methods
__call()
public
__call(string $method, array<string|int, mixed> $args) : PromiseInterface|ResponseInterface
Client::__call will be removed in guzzlehttp/guzzle:8.0.
Parameters
- $method : string
- $args : array<string|int, mixed>
Return values
PromiseInterface|ResponseInterface__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.
- transport_sharing: (string|null) Transport sharing mode for the default handler. Accepts TransportSharing::* or null. Defaults to null.
- max_host_connections: (int|null) Maximum concurrent connections per host, applied by the default CurlMultiHandler. The default stream fallback receives the cap as a marker only: it rejects enabled response streaming ("stream" => true) and does not limit overlapping buffered calls.
- max_total_connections: (int|null) Maximum concurrent connections overall, applied by the default CurlMultiHandler. The default stream fallback receives the cap as a marker only: it rejects enabled response streaming ("stream" => true) and does not limit overlapping buffered calls.
- multiplex: (string|null) Multiplexing::NONE to disable multiplexing on the default CurlMultiHandler; the value also becomes the default "multiplex" request option. Other Multiplexing::* values act as the default request option only.
- **: any request option
Parameters
- $config : array<string|int, mixed> = []
-
Client configuration settings.
Tags
delete()
Create and send an HTTP DELETE request.
public
delete(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Tags
Return values
ResponseInterfacedeleteAsync()
Create and send an asynchronous HTTP DELETE request.
public
deleteAsync(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Return values
PromiseInterfaceget()
Create and send an HTTP GET request.
public
get(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Tags
Return values
ResponseInterfacegetAsync()
Create and send an asynchronous HTTP GET request.
public
getAsync(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Return values
PromiseInterfacegetConfig()
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.
head()
Create and send an HTTP HEAD request.
public
head(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Tags
Return values
ResponseInterfaceheadAsync()
Create and send an asynchronous HTTP HEAD request.
public
headAsync(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Return values
PromiseInterfacepatch()
Create and send an HTTP PATCH request.
public
patch(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Tags
Return values
ResponseInterfacepatchAsync()
Create and send an asynchronous HTTP PATCH request.
public
patchAsync(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Return values
PromiseInterfacepost()
Create and send an HTTP POST request.
public
post(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Tags
Return values
ResponseInterfacepostAsync()
Create and send an asynchronous HTTP POST request.
public
postAsync(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Return values
PromiseInterfaceput()
Create and send an HTTP PUT request.
public
put(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Tags
Return values
ResponseInterfaceputAsync()
Create and send an asynchronous HTTP PUT request.
public
putAsync(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
- $uri : string|UriInterface
-
URI object or string.
- $options : array<string|int, mixed> = []
-
Request options to apply.
Return values
PromiseInterfacerequest()
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 RequestOptions.
Tags
Return values
ResponseInterfacerequestAsync()
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 RequestOptions.
Return values
PromiseInterfacesend()
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 RequestOptions.
Tags
Return values
ResponseInterfacesendAsync()
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 RequestOptions.
Return values
PromiseInterfacesendRequest()
The HttpClient PSR (PSR-18) specify this method.
public
sendRequest(RequestInterface $request) : ResponseInterface
Parameters
- $request : RequestInterface
Return values
ResponseInterfaceapplyOptions()
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
RequestInterfacebuildUri()
private
buildUri(UriInterface $uri, array<string|int, mixed> $config) : UriInterface
Parameters
- $uri : UriInterface
- $config : array<string|int, mixed>
Return values
UriInterfacecanStringifyDeprecatedValue()
private
static canStringifyDeprecatedValue(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolcastDeprecatedHeaderOptionValues()
private
static castDeprecatedHeaderOptionValues(array<string|int, mixed> &$headers) : array<int, string>
Parameters
- $headers : array<string|int, mixed>
Return values
array<int, string>configureDefaults()
Configures the default options for a client.
private
configureDefaults(array<string|int, mixed> $config) : void
Parameters
- $config : array<string|int, mixed>
createBodyStream()
private
static createBodyStream(mixed $body) : StreamInterface
Parameters
- $body : mixed
Return values
StreamInterfaceinvalidBody()
Return an InvalidArgumentException with pre-set message.
private
invalidBody() : InvalidArgumentException
Return values
InvalidArgumentExceptionisProtocolVersionValid()
private
static isProtocolVersionValid(string $version) : bool
Parameters
- $version : string
Return values
boolnormalizeDeprecatedAuthOptionValues()
private
static normalizeDeprecatedAuthOptionValues(array<string, mixed> &$options) : void
Parameters
- $options : array<string, mixed>
normalizeDeprecatedIntegerOptionValues()
private
static normalizeDeprecatedIntegerOptionValues(array<string, mixed> &$options) : void
Parameters
- $options : array<string, mixed>
normalizeDeprecatedNumericOptionValues()
private
static normalizeDeprecatedNumericOptionValues(array<string, mixed> &$options) : void
Parameters
- $options : array<string, mixed>
normalizeDeprecatedRequestOptionValues()
Normalize values that guzzlehttp/guzzle 8.0 rejects only after the corresponding 7.x deprecation has already been emitted.
private
static normalizeDeprecatedRequestOptionValues(array<string, mixed> $options) : array<string, mixed>
Parameters
- $options : array<string, mixed>
Return values
array<string, mixed>normalizeDeprecatedStringOptionValues()
private
static normalizeDeprecatedStringOptionValues(array<string, mixed> &$options) : void
Parameters
- $options : array<string, mixed>
normalizeDeprecatedTlsFileOptionValues()
private
static normalizeDeprecatedTlsFileOptionValues(array<string, mixed> &$options, string $option) : void
Parameters
- $options : array<string, mixed>
- $option : string
normalizeNonFiniteFloats()
Converts non-finite floats in the array to the strings PHP coerces them to, as implicit coercion of NAN emits a warning on PHP 8.5.
private
static normalizeNonFiniteFloats(array<string|int, mixed> $values, string $option) : array<string|int, mixed>
Parameters
- $values : array<string|int, mixed>
- $option : string
Return values
array<string|int, mixed>normalizeProtocolVersion()
private
static normalizeProtocolVersion(string|int|float $version) : string
Parameters
- $version : string|int|float
Return values
stringprepareDefaults()
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>shouldPreserveHost()
Whether to preserve an existing Host header when the URI changes.
private
static shouldPreserveHost(RequestInterface $request) : bool
A header matching the current URI carries no explicit override and is regenerated after base URI resolution or IDN conversion. Other values are preserved as deliberate overrides, as PSR-7 requires.
Parameters
- $request : RequestInterface
Return values
boolstringifyDeprecatedValue()
private
static stringifyDeprecatedValue(mixed $value) : string
Parameters
- $value : mixed
Return values
stringstringifyScalar()
private
static stringifyScalar(bool|float|int|string $value) : string
Parameters
- $value : bool|float|int|string
Return values
stringtransfer()
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 RequestOptions.
Return values
PromiseInterfacewarnAboutInvalidAllowRedirectsOptionTypes()
private
static warnAboutInvalidAllowRedirectsOptionTypes(array<string|int, mixed> $allowRedirects) : void
Parameters
- $allowRedirects : array<string|int, mixed>
warnAboutInvalidAuthOptionTypes()
private
static warnAboutInvalidAuthOptionTypes(mixed $auth) : void
Parameters
- $auth : mixed
warnAboutInvalidFormParamArray()
private
static warnAboutInvalidFormParamArray(array<string|int, mixed> $values, string $path) : bool
Parameters
- $values : array<string|int, mixed>
- $path : string
Return values
boolwarnAboutInvalidFormParamTypes()
private
static warnAboutInvalidFormParamTypes(mixed $value) : void
Parameters
- $value : mixed
warnAboutInvalidHeaderOptionTypes()
private
static warnAboutInvalidHeaderOptionTypes(mixed $headers) : void
Parameters
- $headers : mixed
warnAboutInvalidMultipartOptionTypes()
private
static warnAboutInvalidMultipartOptionTypes(mixed $multipart) : void
Parameters
- $multipart : mixed
warnAboutInvalidProtocolValues()
private
static warnAboutInvalidProtocolValues(array<string|int, mixed> $options, string $option[, string|null $path = null ]) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
- $path : string|null = null
warnAboutInvalidProxyOptionTypes()
private
static warnAboutInvalidProxyOptionTypes(array<string|int, mixed> $options) : void
Parameters
- $options : array<string|int, mixed>
warnAboutInvalidRequestOptionTypes()
private
static warnAboutInvalidRequestOptionTypes(array<string|int, mixed> $options) : void
Parameters
- $options : array<string|int, mixed>
warnAboutInvalidTlsFileOptionTypes()
private
static warnAboutInvalidTlsFileOptionTypes(array<string|int, mixed> $options, string $option) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
warnAboutRequestLevelHandler()
private
static warnAboutRequestLevelHandler(array<string|int, mixed> $options) : void
Parameters
- $options : array<string|int, mixed>
warnIfPresentAndNotArray()
private
static warnIfPresentAndNotArray(array<string|int, mixed> $options, string $option, string $expected) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
- $expected : string
warnIfPresentAndNotBool()
private
static warnIfPresentAndNotBool(array<string|int, mixed> $options, string $option[, string|null $path = null ]) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
- $path : string|null = null
warnIfPresentAndNotBoolOrInt()
private
static warnIfPresentAndNotBoolOrInt(array<string|int, mixed> $options, string $option) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
warnIfPresentAndNotBoolOrResource()
private
static warnIfPresentAndNotBoolOrResource(array<string|int, mixed> $options, string $option) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
warnIfPresentAndNotBoolOrString()
private
static warnIfPresentAndNotBoolOrString(array<string|int, mixed> $options, string $option) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
warnIfPresentAndNotCallable()
private
static warnIfPresentAndNotCallable(array<string|int, mixed> $options, string $option[, string|null $path = null ][, string $since = '7.11' ]) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
- $path : string|null = null
- $since : string = '7.11'
warnIfPresentAndNotInt()
private
static warnIfPresentAndNotInt(array<string|int, mixed> $options, string $option[, string|null $path = null ][, string $since = '7.11' ]) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
- $path : string|null = null
- $since : string = '7.11'
warnIfPresentAndNotNumber()
private
static warnIfPresentAndNotNumber(array<string|int, mixed> $options, string $option) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
warnIfPresentAndNotString()
private
static warnIfPresentAndNotString(array<string|int, mixed> $options, string $option) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
warnIfPresentAndNotStringArray()
private
static warnIfPresentAndNotStringArray(array<string|int, mixed> $options, string $option, bool $nonEmpty[, string|null $path = null ]) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
- $nonEmpty : bool
- $path : string|null = null
warnIfPresentAndNotStringOrNumber()
private
static warnIfPresentAndNotStringOrNumber(array<string|int, mixed> $options, string $option) : void
Parameters
- $options : array<string|int, mixed>
- $option : string
warnInvalidRequestOptionType()
private
static warnInvalidRequestOptionType(string $option, string $expected, mixed $value[, string $since = '7.11' ]) : void
Parameters
- $option : string
- $expected : string
- $value : mixed
- $since : string = '7.11'