\GuzzleHttp\CommandServiceClient

The Guzzle ServiceClient serves as the foundation for creating web service clients that interact with RPC-style APIs.

Summary

Methods
Properties
Constants
__construct()
getHttpClient()
getHandlerStack()
getCommand()
execute()
executeAsync()
executeAll()
executeAllAsync()
__call()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
createCommandHandler()
transformCommandToRequest()
transformResponseToResult()
$httpClient
$handlerStack
$commandToRequestTransformer
$responseToResultTransformer
N/A

Properties

$httpClient

$httpClient : \GuzzleHttp\ClientInterface

Type

ClientInterface — HTTP client used to send requests

$handlerStack

$handlerStack : \GuzzleHttp\HandlerStack

Type

HandlerStack

$commandToRequestTransformer

$commandToRequestTransformer : callable

Type

callable

$responseToResultTransformer

$responseToResultTransformer : callable

Type

callable

Methods

__construct()

__construct(\GuzzleHttp\ClientInterface  $httpClient, callable  $commandToRequestTransformer, callable  $responseToResultTransformer, \GuzzleHttp\HandlerStack  $commandHandlerStack = null) : mixed

Instantiates a Guzzle ServiceClient for making requests to a web service.

Parameters

\GuzzleHttp\ClientInterface $httpClient

A fully-configured Guzzle HTTP client that will be used to perform the underlying HTTP requests.

callable $commandToRequestTransformer

A callable that transforms a Command into a Request. The function should accept a GuzzleHttp\Command\CommandInterface object and return a Psr\Http\Message\RequestInterface object.

callable $responseToResultTransformer

A callable that transforms a Response into a Result. The function should accept a Psr\Http\Message\ResponseInterface object (and optionally a Psr\Http\Message\RequestInterface object) and return a GuzzleHttp\Command\ResultInterface object.

\GuzzleHttp\HandlerStack $commandHandlerStack

A Guzzle HandlerStack, which can be used to add command-level middleware to the service client.

Returns

mixed —

getHttpClient()

getHttpClient() : \GuzzleHttp\ClientInterface

Get the HTTP client used to send requests for the web service client

Returns

\GuzzleHttp\ClientInterface —

getHandlerStack()

getHandlerStack() : \GuzzleHttp\HandlerStack

Get the HandlerStack which can be used to add middleware to the client.

Returns

\GuzzleHttp\HandlerStack —

getCommand()

getCommand(mixed  $name, array  $params = []) : \GuzzleHttp\Command\CommandInterface

Create a command for an operation name.

Special keys may be set on the command to control how it behaves. Implementations SHOULD be able to utilize the following keys or throw an exception if unable.

Parameters

mixed $name

Name of the operation to use in the command

array $params

Returns

\GuzzleHttp\Command\CommandInterface —

execute()

execute(\GuzzleHttp\Command\CommandInterface  $command) : \GuzzleHttp\Command\ResultInterface

Execute a single command.

Parameters

\GuzzleHttp\Command\CommandInterface $command

Command to execute

Returns

\GuzzleHttp\Command\ResultInterface —

The result of the executed command

executeAsync()

executeAsync(\GuzzleHttp\Command\CommandInterface  $command) : \GuzzleHttp\Promise\PromiseInterface

Execute a single command asynchronously

Parameters

\GuzzleHttp\Command\CommandInterface $command

Command to execute

Returns

\GuzzleHttp\Promise\PromiseInterface —

A Promise that resolves to a Result.

executeAll()

executeAll(mixed  $commands, array  $options = []) : array

Executes multiple commands concurrently using a fixed pool size.

Parameters

mixed $commands

Array or iterator that contains CommandInterface objects to execute with the client.

array $options

Associative array of options to apply.

  • concurrency: (int) Max number of commands to execute concurrently.
  • fulfilled: (callable) Function to invoke when a command completes.
  • rejected: (callable) Function to invoke when a command fails.

Returns

array —

executeAllAsync()

executeAllAsync(mixed  $commands, array  $options = []) : \GuzzleHttp\Promise\PromiseInterface

Executes multiple commands concurrently and asynchronously using a fixed pool size.

Parameters

mixed $commands

Array or iterator that contains CommandInterface objects to execute with the client.

array $options

Associative array of options to apply.

  • concurrency: (int) Max number of commands to execute concurrently.
  • fulfilled: (callable) Function to invoke when a command completes.
  • rejected: (callable) Function to invoke when a command fails.

Returns

\GuzzleHttp\Promise\PromiseInterface —

__call()

__call(string  $name, array  $args) : \GuzzleHttp\Command\ResultInterface|\GuzzleHttp\Promise\PromiseInterface

Creates and executes a command for an operation by name.

Parameters

string $name

Name of the command to execute.

array $args

Arguments to pass to the getCommand method.

Returns

\GuzzleHttp\Command\ResultInterface|\GuzzleHttp\Promise\PromiseInterface —

createCommandHandler()

createCommandHandler() : callable

Defines the main handler for commands that uses the HTTP client.

Returns

callable —

transformCommandToRequest()

transformCommandToRequest(\GuzzleHttp\Command\CommandInterface  $command) : \Psr\Http\Message\RequestInterface

Transforms a Command object into a Request object.

Parameters

\GuzzleHttp\Command\CommandInterface $command

Returns

\Psr\Http\Message\RequestInterface —

transformResponseToResult()

transformResponseToResult(\Psr\Http\Message\ResponseInterface  $response, \Psr\Http\Message\RequestInterface  $request, \GuzzleHttp\Command\CommandInterface  $command) : \GuzzleHttp\Command\ResultInterface

Transforms a Response object, also using data from the Request object, into a Result object.

Parameters

\Psr\Http\Message\ResponseInterface $response
\Psr\Http\Message\RequestInterface $request
\GuzzleHttp\Command\CommandInterface $command

Returns

\GuzzleHttp\Command\ResultInterface —