Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

(no description)

File Size: 477 lines (18 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Client:: (14 methods):
  __construct()
  __call()
  sendAsync()
  send()
  sendRequest()
  requestAsync()
  request()
  getConfig()
  buildUri()
  configureDefaults()
  prepareDefaults()
  transfer()
  applyOptions()
  invalidBody()


Class: Client  - X-Ref


__construct(array $config = [])   X-Ref
Clients accept an array of constructor parameters.

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.
- **: any request option

param: array $config Client configuration settings.

__call($method, $args)   X-Ref

param: string $method
param: array  $args
return: PromiseInterface|ResponseInterface

sendAsync(RequestInterface $request, array $options = [])   X-Ref
Asynchronously send an HTTP request.

param: array $options Request options to apply to the given

send(RequestInterface $request, array $options = [])   X-Ref
Send an HTTP request.

param: array $options Request options to apply to the given

sendRequest(RequestInterface $request)   X-Ref
The HttpClient PSR (PSR-18) specify this method.


requestAsync(string $method, $uri = '', array $options = [])   X-Ref
Create and send an asynchronous HTTP request.

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.

param: string              $method  HTTP method
param: string|UriInterface $uri     URI object or string.
param: array               $options Request options to apply. See \GuzzleHttp\RequestOptions.

request(string $method, $uri = '', array $options = [])   X-Ref
Create and send an HTTP request.

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.

param: string              $method  HTTP method.
param: string|UriInterface $uri     URI object or string.
param: array               $options Request options to apply. See \GuzzleHttp\RequestOptions.

getConfig(?string $option = null)   X-Ref
Get a client configuration option.

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.

param: string|null $option The config option to retrieve.
return: mixed

buildUri(UriInterface $uri, array $config)   X-Ref
No description

configureDefaults(array $config)   X-Ref
Configures the default options for a client.


prepareDefaults(array $options)   X-Ref
Merges default options into the array.

param: array $options Options to modify by reference

transfer(RequestInterface $request, array $options)   X-Ref
Transfers the given request and applies request options.

The URI of the request is not modified and the request options are used
as-is without merging in default options.

param: array $options See \GuzzleHttp\RequestOptions.

applyOptions(RequestInterface $request, array &$options)   X-Ref
Applies the array of request options to a request.


invalidBody()   X-Ref
Return an InvalidArgumentException with pre-set message.