Client
extends AbstractHasDispatcher
in package
implements
ClientInterface
HTTP client
Table of Contents
Interfaces
- ClientInterface
- Client interface for send HTTP requests
Constants
- CURL_OPTIONS = 'curl.options'
- DEFAULT_SELECT_TIMEOUT = 1.0
- DISABLE_REDIRECTS = \Guzzle\Http\RedirectPlugin::DISABLE
- MAX_HANDLES = 3
- REQUEST_OPTIONS = 'request.options'
- REQUEST_PARAMS = 'request.params'
- SSL_CERT_AUTHORITY = 'ssl.certificate_authority'
Properties
- $defaultHeaders : Collection
- $eventDispatcher : EventDispatcherInterface
- $requestFactory : RequestFactoryInterface
- $userAgent : string
- $baseUrl : Url
- $config : Collection
- $curlMulti : CurlMultiInterface
- $uriTemplate : UriTemplateInterface
Methods
- __construct() : mixed
- addSubscriber() : self
- Add an event subscriber to the dispatcher
- createRequest() : RequestInterface
- Create and return a new {@see RequestInterface} configured for the client.
- delete() : EntityEnclosingRequestInterface
- Create a DELETE request for the client
- dispatch() : Event
- Helper to dispatch Guzzle events and set the event name on the event
- extractPharCacert() : string
- Copies the phar cacert from a phar into the temp directory.
- get() : RequestInterface
- Create a GET request for the client
- getAllEvents() : array<string|int, mixed>
- Get a list of all of the events emitted from the class
- getBaseUrl() : string|null
- Get the client's base URL as either an expanded or raw URI template
- getConfig() : mixed|Collection
- Get a configuration setting or all of the configuration settings. The Collection result of this method can be modified to change the configuration settings of a client.
- getCurlMulti() : CurlMultiInterface|CurlMultiProxy
- getDefaultHeaders() : mixed
- getDefaultOption() : mixed|null
- Retrieve a default request option from the client
- getDefaultUserAgent() : string
- Get the default User-Agent string to use with Guzzle
- getEventDispatcher() : EventDispatcherInterface
- Get the EventDispatcher of the request
- head() : RequestInterface
- Create a HEAD request for the client
- options() : RequestInterface
- Create an OPTIONS request for the client
- patch() : EntityEnclosingRequestInterface
- Create a PATCH request for the client
- post() : EntityEnclosingRequestInterface
- Create a POST request for the client
- preparePharCacert() : mixed
- put() : EntityEnclosingRequestInterface
- Create a PUT request for the client
- send() : Response|array<string|int, mixed>
- Sends a single request or an array of requests in parallel
- setBaseUrl() : self
- Set the base URL of the client
- setConfig() : self
- Set the configuration object to use with the client
- setCurlMulti() : self
- Set a curl multi object to be used internally by the client for transferring requests.
- setDefaultHeaders() : mixed
- setDefaultOption() : $this
- Set a default request option on the client that will be used as a default for each request
- setEventDispatcher() : self
- Set the EventDispatcher of the request
- setRequestFactory() : mixed
- setSslVerification() : self
- Set SSL verification options.
- setUriTemplate() : self
- Set the URI template expander to use with the client
- setUserAgent() : self
- Set the User-Agent header to be used on all requests from the client
- expandTemplate() : string
- Expand a URI template while merging client config settings into the template variables
- getUriTemplate() : UriTemplateInterface
- Get the URI template expander used by the client
- initSsl() : mixed
- Initializes SSL settings
- prepareRequest() : RequestInterface
- Prepare a request to be sent from the Client by adding client specific behaviors and properties to the request.
- sendMultiple() : array<string|int, mixed>
- Send multiple requests in parallel
Constants
CURL_OPTIONS
public
mixed
CURL_OPTIONS
= 'curl.options'
DEFAULT_SELECT_TIMEOUT
public
mixed
DEFAULT_SELECT_TIMEOUT
= 1.0
DISABLE_REDIRECTS
public
mixed
DISABLE_REDIRECTS
= \Guzzle\Http\RedirectPlugin::DISABLE
MAX_HANDLES
public
mixed
MAX_HANDLES
= 3
REQUEST_OPTIONS
public
mixed
REQUEST_OPTIONS
= 'request.options'
REQUEST_PARAMS
Use [request.options][params]
public
mixed
REQUEST_PARAMS
= 'request.params'
SSL_CERT_AUTHORITY
public
mixed
SSL_CERT_AUTHORITY
= 'ssl.certificate_authority'
Properties
$defaultHeaders
protected
Collection
$defaultHeaders
Default HTTP headers to set on each request
$eventDispatcher
protected
EventDispatcherInterface
$eventDispatcher
$requestFactory
protected
RequestFactoryInterface
$requestFactory
Request factory used by the client
$userAgent
protected
string
$userAgent
The user agent string to set on each request
$baseUrl
private
Url
$baseUrl
Base URL of the client
$config
private
Collection
$config
Parameter object holding configuration data
$curlMulti
private
CurlMultiInterface
$curlMulti
CurlMulti object used internally
$uriTemplate
private
UriTemplateInterface
$uriTemplate
URI template owned by the client
Methods
__construct()
public
__construct([string $baseUrl = '' ][, array<string|int, mixed>|Collection $config = null ]) : mixed
Parameters
- $baseUrl : string = ''
-
Base URL of the web service
- $config : array<string|int, mixed>|Collection = null
-
Configuration settings
Tags
addSubscriber()
Add an event subscriber to the dispatcher
public
addSubscriber(EventSubscriberInterface $subscriber) : self
Parameters
- $subscriber : EventSubscriberInterface
-
Event subscriber
Return values
selfcreateRequest()
Create and return a new {@see RequestInterface} configured for the client.
public
createRequest([mixed $method = 'GET' ][, mixed $uri = null ][, mixed $headers = null ][, mixed $body = null ][, array<string|int, mixed> $options = array() ]) : RequestInterface
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 URI can contain the query string as well. Use an array to provide a URI template and additional variables to use in the URI template expansion.
Parameters
- $method : mixed = 'GET'
-
HTTP method. Defaults to GET
- $uri : mixed = null
-
Resource URI.
- $headers : mixed = null
-
HTTP headers
- $body : mixed = null
-
Entity body of request (POST/PUT) or response (GET)
- $options : array<string|int, mixed> = array()
-
Array of options to apply to the request
Return values
RequestInterfacedelete()
Create a DELETE request for the client
public
delete([mixed $uri = null ][, mixed $headers = null ][, mixed $body = null ][, array<string|int, mixed> $options = array() ]) : EntityEnclosingRequestInterface
Parameters
- $uri : mixed = null
-
Resource URI
- $headers : mixed = null
-
HTTP headers
- $body : mixed = null
-
Body to send in the request
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Return values
EntityEnclosingRequestInterfacedispatch()
Helper to dispatch Guzzle events and set the event name on the event
public
dispatch(mixed $eventName[, array<string|int, mixed> $context = array() ]) : Event
Parameters
- $eventName : mixed
-
Name of the event to dispatch
- $context : array<string|int, mixed> = array()
-
Context of the event
Return values
Event —Returns the created event object
extractPharCacert()
Copies the phar cacert from a phar into the temp directory.
public
static extractPharCacert(string $pharCacertPath) : string
Parameters
- $pharCacertPath : string
-
Path to the phar cacert. For example: 'phar://aws.phar/Guzzle/Http/Resources/cacert.pem'
Tags
Return values
string —Returns the path to the extracted cacert file.
get()
Create a GET request for the client
public
get([mixed $uri = null ][, mixed $headers = null ][, mixed $options = array() ]) : RequestInterface
Parameters
- $uri : mixed = null
-
Resource URI
- $headers : mixed = null
-
HTTP headers
- $options : mixed = array()
-
Options to apply to the request. For BC compatibility, you can also pass a string to tell Guzzle to download the body of the response to a particular location. Use the 'body' option instead for forward compatibility.
Return values
RequestInterfacegetAllEvents()
Get a list of all of the events emitted from the class
public
static getAllEvents() : array<string|int, mixed>
Return values
array<string|int, mixed>getBaseUrl()
Get the client's base URL as either an expanded or raw URI template
public
getBaseUrl([mixed $expand = true ]) : string|null
Parameters
- $expand : mixed = true
-
Set to FALSE to get the raw base URL without URI template expansion
Return values
string|nullgetConfig()
Get a configuration setting or all of the configuration settings. The Collection result of this method can be modified to change the configuration settings of a client.
public
final getConfig([mixed $key = false ]) : mixed|Collection
A client should honor the following special values:
- request.options: Associative array of default RequestFactory options to apply to each request
- request.params: Associative array of request parameters (data values) to apply to each request
- curl.options: Associative array of cURL configuration settings to apply to each request
- ssl.certificate_authority: Path a CAINFO, CAPATH, true to use strict defaults, or false to disable verification
- redirect.disable: Set to true to disable redirects
Parameters
- $key : mixed = false
-
Configuration value to retrieve. Set to FALSE to retrieve all values of the client. The object return can be modified, and modifications will affect the client's config.
Return values
mixed|CollectiongetCurlMulti()
public
getCurlMulti() : CurlMultiInterface|CurlMultiProxy
Return values
CurlMultiInterface|CurlMultiProxygetDefaultHeaders()
public
getDefaultHeaders() : mixed
getDefaultOption()
Retrieve a default request option from the client
public
getDefaultOption(string $keyOrPath) : mixed|null
Parameters
- $keyOrPath : string
-
request.options key (e.g. allow_redirects) or path to a nested key (e.g. headers/foo)
Return values
mixed|nullgetDefaultUserAgent()
Get the default User-Agent string to use with Guzzle
public
getDefaultUserAgent() : string
Return values
stringgetEventDispatcher()
Get the EventDispatcher of the request
public
getEventDispatcher() : EventDispatcherInterface
Return values
EventDispatcherInterfacehead()
Create a HEAD request for the client
public
head([mixed $uri = null ][, mixed $headers = null ][, array<string|int, mixed> $options = array() ]) : RequestInterface
Parameters
- $uri : mixed = null
-
Resource URI
- $headers : mixed = null
-
HTTP headers
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Return values
RequestInterfaceoptions()
Create an OPTIONS request for the client
public
options([mixed $uri = null ][, array<string|int, mixed> $options = array() ]) : RequestInterface
Parameters
- $uri : mixed = null
-
Resource URI
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Return values
RequestInterfacepatch()
Create a PATCH request for the client
public
patch([mixed $uri = null ][, mixed $headers = null ][, mixed $body = null ][, array<string|int, mixed> $options = array() ]) : EntityEnclosingRequestInterface
Parameters
- $uri : mixed = null
-
Resource URI
- $headers : mixed = null
-
HTTP headers
- $body : mixed = null
-
Body to send in the request
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Return values
EntityEnclosingRequestInterfacepost()
Create a POST request for the client
public
post([mixed $uri = null ][, mixed $headers = null ][, mixed $postBody = null ][, array<string|int, mixed> $options = array() ]) : EntityEnclosingRequestInterface
Parameters
- $uri : mixed = null
-
Resource URI
- $headers : mixed = null
-
HTTP headers
- $postBody : mixed = null
-
POST body. Can be a string, EntityBody, or associative array of POST fields to send in the body of the request. Prefix a value in the array with the @ symbol to reference a file.
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Return values
EntityEnclosingRequestInterfacepreparePharCacert()
public
preparePharCacert([mixed $md5Check = true ]) : mixed
Parameters
- $md5Check : mixed = true
put()
Create a PUT request for the client
public
put([mixed $uri = null ][, mixed $headers = null ][, mixed $body = null ][, array<string|int, mixed> $options = array() ]) : EntityEnclosingRequestInterface
Parameters
- $uri : mixed = null
-
Resource URI
- $headers : mixed = null
-
HTTP headers
- $body : mixed = null
-
Body to send in the request
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Return values
EntityEnclosingRequestInterfacesend()
Sends a single request or an array of requests in parallel
public
send(mixed $requests) : Response|array<string|int, mixed>
Parameters
- $requests : mixed
-
One or more RequestInterface objects to send
Return values
Response|array<string|int, mixed> —Returns a single Response or an array of Response objects
setBaseUrl()
Set the base URL of the client
public
setBaseUrl(mixed $url) : self
Parameters
- $url : mixed
-
The base service endpoint URL of the webservice
Return values
selfsetConfig()
Set the configuration object to use with the client
public
final setConfig(mixed $config) : self
Parameters
- $config : mixed
-
Parameters that define how the client behaves
Return values
selfsetCurlMulti()
Set a curl multi object to be used internally by the client for transferring requests.
public
setCurlMulti(CurlMultiInterface $curlMulti) : self
Parameters
- $curlMulti : CurlMultiInterface
-
Multi object
Return values
selfsetDefaultHeaders()
public
setDefaultHeaders(mixed $headers) : mixed
Parameters
- $headers : mixed
setDefaultOption()
Set a default request option on the client that will be used as a default for each request
public
setDefaultOption(string $keyOrPath, mixed $value) : $this
Parameters
- $keyOrPath : string
-
request.options key (e.g. allow_redirects) or path to a nested key (e.g. headers/foo)
- $value : mixed
-
Value to set
Return values
$thissetEventDispatcher()
Set the EventDispatcher of the request
public
setEventDispatcher(EventDispatcherInterface $eventDispatcher) : self
Parameters
- $eventDispatcher : EventDispatcherInterface
Return values
selfsetRequestFactory()
public
setRequestFactory(RequestFactoryInterface $factory) : mixed
Parameters
- $factory : RequestFactoryInterface
setSslVerification()
Set SSL verification options.
public
final setSslVerification([mixed $certificateAuthority = true ][, mixed $verifyPeer = true ][, mixed $verifyHost = 2 ]) : self
Setting $certificateAuthority to TRUE will result in the bundled cacert.pem being used to verify against the remote host.
Alternate certificates to verify against can be specified with the $certificateAuthority option set to the full path to a certificate file, or the path to a directory containing certificates.
Setting $certificateAuthority to FALSE will turn off peer verification, unset the bundled cacert.pem, and disable host verification. Please don't do this unless you really know what you're doing, and why you're doing it.
Parameters
- $certificateAuthority : mixed = true
-
bool, file path, or directory path
- $verifyPeer : mixed = true
-
FALSE to stop from verifying the peer's certificate.
- $verifyHost : mixed = 2
-
Set to 1 to check the existence of a common name in the SSL peer certificate. 2 to check the existence of a common name and also verify that it matches the hostname provided.
Return values
selfsetUriTemplate()
Set the URI template expander to use with the client
public
setUriTemplate(UriTemplateInterface $uriTemplate) : self
Parameters
- $uriTemplate : UriTemplateInterface
-
URI template expander
Return values
selfsetUserAgent()
Set the User-Agent header to be used on all requests from the client
public
setUserAgent(mixed $userAgent[, mixed $includeDefault = false ]) : self
Parameters
- $userAgent : mixed
-
User agent string
- $includeDefault : mixed = false
-
Set to true to prepend the value to Guzzle's default user agent string
Return values
selfexpandTemplate()
Expand a URI template while merging client config settings into the template variables
protected
expandTemplate(string $template[, array<string|int, mixed> $variables = null ]) : string
Parameters
- $template : string
-
Template to expand
- $variables : array<string|int, mixed> = null
-
Variables to inject
Return values
stringgetUriTemplate()
Get the URI template expander used by the client
protected
getUriTemplate() : UriTemplateInterface
Return values
UriTemplateInterfaceinitSsl()
Initializes SSL settings
protected
initSsl() : mixed
prepareRequest()
Prepare a request to be sent from the Client by adding client specific behaviors and properties to the request.
protected
prepareRequest(RequestInterface $request[, array<string|int, mixed> $options = array() ]) : RequestInterface
Parameters
- $request : RequestInterface
-
Request to prepare for the client
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Return values
RequestInterfacesendMultiple()
Send multiple requests in parallel
protected
sendMultiple(array<string|int, mixed> $requests) : array<string|int, mixed>
Parameters
- $requests : array<string|int, mixed>
-
Array of RequestInterface objects
Return values
array<string|int, mixed> —Returns an array of Response objects