Documentation

Client extends Client
in package
implements ClientInterface

Client object for executing commands on a web service.

Table of Contents

Interfaces

ClientInterface
Client interface for executing commands on a web service.

Constants

COMMAND_PARAMS  = 'command.params'
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

$commandFactory  : FactoryInterface
$defaultHeaders  : Collection
$eventDispatcher  : EventDispatcherInterface
$inflector  : InflectorInterface
$requestFactory  : RequestFactoryInterface
$resourceIteratorFactory  : ResourceIteratorFactoryInterface
$serviceDescription  : ServiceDescriptionInterface
$userAgent  : string
$baseUrl  : Url
$config  : Collection
$curlMulti  : CurlMultiInterface
$uriTemplate  : UriTemplateInterface

Methods

__call()  : mixed
Magic method used to retrieve a command
__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
enableMagicMethods()  : mixed
execute()  : mixed
Execute one or more commands
extractPharCacert()  : string
Copies the phar cacert from a phar into the temp directory.
factory()  : Client
Basic factory method to create a new client. Extend this method in subclasses to build more complex clients.
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
getCommand()  : CommandInterface
Get a command by name. First, the client will see if it has a service description and if the service description defines a command by the supplied name. If no dynamic command is found, the client will look for a concrete command class exists matching the name supplied. If neither are found, an InvalidArgumentException is thrown.
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
getDescription()  : ServiceDescriptionInterface|null
Get the service description of the client
getEventDispatcher()  : EventDispatcherInterface
Get the EventDispatcher of the request
getInflector()  : self
Get the inflector used with the client
getIterator()  : ResourceIteratorInterface
Get a resource iterator from the client.
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
setCommandFactory()  : self
Set the command factory used to create commands by name
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
setDescription()  : ClientInterface
Set the service description of the client
setEventDispatcher()  : self
Set the EventDispatcher of the request
setInflector()  : self
Set the inflector used with the client
setRequestFactory()  : mixed
setResourceIteratorFactory()  : self
Set the resource iterator factory associated with the client
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
executeMultiple()  : array<string|int, mixed>
Execute multiple commands in parallel
expandTemplate()  : string
Expand a URI template while merging client config settings into the template variables
getCommandFactory()  : FactoryInterface
Get the command factory associated with the client
getResourceIteratorFactory()  : mixed
getUriTemplate()  : UriTemplateInterface
Get the URI template expander used by the client
initSsl()  : mixed
Initializes SSL settings
prepareCommand()  : RequestInterface
Prepare a command for sending and get the RequestInterface object created by the command
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

COMMAND_PARAMS

public mixed COMMAND_PARAMS = 'command.params'

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

$userAgent

protected string $userAgent

The user agent string to set on each request

$baseUrl

private Url $baseUrl

Base URL of the client

Methods

__call()

Magic method used to retrieve a command

public __call(string $method, array<string|int, mixed> $args) : mixed
Parameters
$method : string

Name of the command object to instantiate

$args : array<string|int, mixed>

Arguments to pass to the command

Tags
throws
BadMethodCallException

when a command is not found

Return values
mixed

Returns the result of the command

__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
throws
RuntimeException

if cURL is not installed

createRequest()

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
RequestInterface

delete()

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
EntityEnclosingRequestInterface

dispatch()

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

enableMagicMethods()

public enableMagicMethods(mixed $isEnabled) : mixed
Parameters
$isEnabled : mixed
Tags
codeCoverageIgnore

execute()

Execute one or more commands

public execute(mixed $command) : mixed
Parameters
$command : mixed

Command, array of commands or Traversable object containing commands to execute

Return values
mixed

Returns the result of the executed command or an array of commands if executing multiple commands

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
throws
RuntimeException

Throws if the phar cacert cannot be found or the file cannot be copied to the temp dir.

Return values
string

Returns the path to the extracted cacert file.

factory()

Basic factory method to create a new client. Extend this method in subclasses to build more complex clients.

public static factory([array<string|int, mixed>|Collection $config = array() ]) : Client
Parameters
$config : array<string|int, mixed>|Collection = array()

Configuration data

Return values
Client

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
RequestInterface

getAllEvents()

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|null

getCommand()

Get a command by name. First, the client will see if it has a service description and if the service description defines a command by the supplied name. If no dynamic command is found, the client will look for a concrete command class exists matching the name supplied. If neither are found, an InvalidArgumentException is thrown.

public getCommand(mixed $name[, array<string|int, mixed> $args = array() ]) : CommandInterface
Parameters
$name : mixed

Name of the command to retrieve

$args : array<string|int, mixed> = array()

Arguments to pass to the command

Return values
CommandInterface

getConfig()

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|Collection

getDefaultHeaders()

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|null

getDefaultUserAgent()

Get the default User-Agent string to use with Guzzle

public getDefaultUserAgent() : string
Return values
string

getInflector()

Get the inflector used with the client

public getInflector() : self
Return values
self

getIterator()

Get a resource iterator from the client.

public getIterator(mixed $command[, array<string|int, mixed> $commandOptions = null ][, array<string|int, mixed> $iteratorOptions = array() ]) : ResourceIteratorInterface
Parameters
$command : mixed

Command class or command name.

$commandOptions : array<string|int, mixed> = null

Command options used when creating commands.

$iteratorOptions : array<string|int, mixed> = array()

Iterator options passed to the iterator when it is instantiated.

Return values
ResourceIteratorInterface

head()

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
RequestInterface

options()

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
RequestInterface

patch()

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
EntityEnclosingRequestInterface

post()

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
EntityEnclosingRequestInterface

preparePharCacert()

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
EntityEnclosingRequestInterface

send()

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
self

setCommandFactory()

Set the command factory used to create commands by name

public setCommandFactory(FactoryInterface $factory) : self
Parameters
$factory : FactoryInterface

Command factory

Return values
self

setConfig()

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
self

setCurlMulti()

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
self

setDefaultHeaders()

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
$this

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
self

setUserAgent()

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
self

executeMultiple()

Execute multiple commands in parallel

protected executeMultiple(array<string|int, mixed>|Traversable $commands) : array<string|int, mixed>
Parameters
$commands : array<string|int, mixed>|Traversable

Array of CommandInterface objects to execute

Tags
throws
CommandTransferException
Return values
array<string|int, mixed>

Returns an array of the executed commands

expandTemplate()

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
string

getResourceIteratorFactory()

protected getResourceIteratorFactory() : mixed

initSsl()

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
RequestInterface

sendMultiple()

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


        
On this page

Search results