ClientInterface
extends
HasDispatcherInterface
in
Client interface for send HTTP requests
Table of Contents
Constants
- CREATE_REQUEST = 'client.create_request'
- HTTP_DATE = 'D, d M Y H:i:s \G\M\T'
Methods
- 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
- 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.
- 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
- 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
- setEventDispatcher() : self
- Set the EventDispatcher of the request
- setSslVerification() : self
- Set SSL verification options.
- setUserAgent() : self
- Set the User-Agent header to be used on all requests from the client
Constants
CREATE_REQUEST
public
mixed
CREATE_REQUEST
= 'client.create_request'
HTTP_DATE
public
string
HTTP_DATE
= 'D, d M Y H:i:s \G\M\T'
RFC 1123 HTTP-Date
Methods
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([string $method = RequestInterface::GET ][, string|array<string|int, mixed> $uri = null ][, array<string|int, mixed>|Collection $headers = null ][, string|resource|array<string|int, mixed>|EntityBodyInterface $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 : string = RequestInterface::GET
-
HTTP method. Defaults to GET
- $uri : string|array<string|int, mixed> = null
-
Resource URI.
- $headers : array<string|int, mixed>|Collection = null
-
HTTP headers
- $body : string|resource|array<string|int, mixed>|EntityBodyInterface = null
-
Entity body of request (POST/PUT) or response (GET)
- $options : array<string|int, mixed> = array()
-
Array of options to apply to the request
Tags
Return values
RequestInterfacedelete()
Create a DELETE request for the client
public
delete([string|array<string|int, mixed> $uri = null ][, array<string|int, mixed>|Collection $headers = null ][, string|resource|EntityBodyInterface $body = null ][, array<string|int, mixed> $options = array() ]) : EntityEnclosingRequestInterface
Parameters
- $uri : string|array<string|int, mixed> = null
-
Resource URI
- $headers : array<string|int, mixed>|Collection = null
-
HTTP headers
- $body : string|resource|EntityBodyInterface = null
-
Body to send in the request
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Tags
Return values
EntityEnclosingRequestInterfacedispatch()
Helper to dispatch Guzzle events and set the event name on the event
public
dispatch(string $eventName[, array<string|int, mixed> $context = array() ]) : Event
Parameters
- $eventName : string
-
Name of the event to dispatch
- $context : array<string|int, mixed> = array()
-
Context of the event
Return values
Event —Returns the created event object
get()
Create a GET request for the client
public
get([string|array<string|int, mixed> $uri = null ][, array<string|int, mixed>|Collection $headers = null ][, array<string|int, mixed> $options = array() ]) : RequestInterface
Parameters
- $uri : string|array<string|int, mixed> = null
-
Resource URI
- $headers : array<string|int, mixed>|Collection = null
-
HTTP headers
- $options : array<string|int, 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.
Tags
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([bool $expand = true ]) : string|null
Parameters
- $expand : bool = 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
getConfig([bool|string $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 : bool|string = 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.
Tags
Return values
mixed|CollectiongetEventDispatcher()
Get the EventDispatcher of the request
public
getEventDispatcher() : EventDispatcherInterface
Return values
EventDispatcherInterfacehead()
Create a HEAD request for the client
public
head([string|array<string|int, mixed> $uri = null ][, array<string|int, mixed>|Collection $headers = null ][, array<string|int, mixed> $options = array() ]) : RequestInterface
Parameters
- $uri : string|array<string|int, mixed> = null
-
Resource URI
- $headers : array<string|int, mixed>|Collection = null
-
HTTP headers
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Tags
Return values
RequestInterfaceoptions()
Create an OPTIONS request for the client
public
options([string|array<string|int, mixed> $uri = null ][, array<string|int, mixed> $options = array() ]) : RequestInterface
Parameters
- $uri : string|array<string|int, mixed> = null
-
Resource URI
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Tags
Return values
RequestInterfacepatch()
Create a PATCH request for the client
public
patch([string|array<string|int, mixed> $uri = null ][, array<string|int, mixed>|Collection $headers = null ][, string|resource|EntityBodyInterface $body = null ][, array<string|int, mixed> $options = array() ]) : EntityEnclosingRequestInterface
Parameters
- $uri : string|array<string|int, mixed> = null
-
Resource URI
- $headers : array<string|int, mixed>|Collection = null
-
HTTP headers
- $body : string|resource|EntityBodyInterface = null
-
Body to send in the request
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Tags
Return values
EntityEnclosingRequestInterfacepost()
Create a POST request for the client
public
post([string|array<string|int, mixed> $uri = null ][, array<string|int, mixed>|Collection $headers = null ][, array<string|int, mixed>|Collection|string|EntityBodyInterface $postBody = null ][, array<string|int, mixed> $options = array() ]) : EntityEnclosingRequestInterface
Parameters
- $uri : string|array<string|int, mixed> = null
-
Resource URI
- $headers : array<string|int, mixed>|Collection = null
-
HTTP headers
- $postBody : array<string|int, mixed>|Collection|string|EntityBodyInterface = 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
Tags
Return values
EntityEnclosingRequestInterfaceput()
Create a PUT request for the client
public
put([string|array<string|int, mixed> $uri = null ][, array<string|int, mixed>|Collection $headers = null ][, string|resource|EntityBodyInterface $body = null ][, array<string|int, mixed> $options = array() ]) : EntityEnclosingRequestInterface
Parameters
- $uri : string|array<string|int, mixed> = null
-
Resource URI
- $headers : array<string|int, mixed>|Collection = null
-
HTTP headers
- $body : string|resource|EntityBodyInterface = null
-
Body to send in the request
- $options : array<string|int, mixed> = array()
-
Options to apply to the request
Tags
Return values
EntityEnclosingRequestInterfacesend()
Sends a single request or an array of requests in parallel
public
send(array<string|int, mixed>|RequestInterface $requests) : Response|array<string|int, mixed>
Parameters
- $requests : array<string|int, mixed>|RequestInterface
-
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(string $url) : self
Parameters
- $url : string
-
The base service endpoint URL of the webservice
Return values
selfsetConfig()
Set the configuration object to use with the client
public
setConfig(array<string|int, mixed>|Collection $config) : self
Parameters
- $config : array<string|int, mixed>|Collection
-
Parameters that define how the client behaves
Return values
selfsetEventDispatcher()
Set the EventDispatcher of the request
public
setEventDispatcher(EventDispatcherInterface $eventDispatcher) : self
Parameters
- $eventDispatcher : EventDispatcherInterface
Return values
selfsetSslVerification()
Set SSL verification options.
public
setSslVerification([string|bool $certificateAuthority = true ][, bool $verifyPeer = true ][, int $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 : string|bool = true
-
bool, file path, or directory path
- $verifyPeer : bool = true
-
FALSE to stop from verifying the peer's certificate.
- $verifyHost : int = 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
selfsetUserAgent()
Set the User-Agent header to be used on all requests from the client
public
setUserAgent(string $userAgent[, bool $includeDefault = false ]) : self
Parameters
- $userAgent : string
-
User agent string
- $includeDefault : bool = false
-
Set to true to prepend the value to Guzzle's default user agent string