Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
core\http_client Class Reference
Inheritance diagram for core\http_client:
GuzzleHttp\Client GuzzleHttp\ClientInterface Psr\Http\Client\ClientInterface

Public Member Functions

 __construct (array $config=[])
 Clients accept an array of constructor parameters.
 
 __call ($method, $args)
 
 getConfig (?string $option=null)
 Get a client configuration option.
 
 request (string $method, $uri='', array $options=[])
 Create and send an HTTP request.
 
 requestAsync (string $method, $uri='', array $options=[])
 Create and send an asynchronous HTTP request.
 
 send (RequestInterface $request, array $options=[])
 Send an HTTP request.
 
 sendAsync (RequestInterface $request, array $options=[])
 Asynchronously send an HTTP request.
 
 sendRequest (RequestInterface $request)
 The HttpClient PSR (PSR-18) specify this method.
 

Public Attributes

const MAJOR_VERSION = 7
 The Guzzle major version.
 

Protected Member Functions

 get_handlers (array $settings)
 Get the handler stack according to the settings/options from client.
 
 get_options (array $settings)
 Get the custom options and handlers for guzzle integration in moodle.
 
 get_proxy (array $settings)
 Get the proxy server identified.
 
 setup_proxy (array $settings)
 Get the proxy configuration.
 

Constructor & Destructor Documentation

◆ __construct()

core\http_client::__construct ( array $config = [])

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
Parameters
array$configClient configuration settings.
See also
GuzzleHttp\RequestOptions for a list of available request options.

Reimplemented from GuzzleHttp\Client.

Member Function Documentation

◆ __call()

GuzzleHttp\Client::__call ( $method,
$args )
inherited
Parameters
string$method
array$args
Return values
PromiseInterface|ResponseInterface
Deprecated
Client\__call will be removed in guzzlehttp/guzzle:8.0.

◆ get_handlers()

core\http_client::get_handlers ( array $settings)
protected

Get the handler stack according to the settings/options from client.

Parameters
array$settingsThe settings or options from client.
Return values
HandlerStack

◆ get_options()

core\http_client::get_options ( array $settings)
protected

Get the custom options and handlers for guzzle integration in moodle.

Parameters
array$settingsThe settings or options from client.
Return values
array

◆ get_proxy()

core\http_client::get_proxy ( array $settings)
protected

Get the proxy server identified.

Parameters
array$settingsThe incoming settings.
Return values
stringThe URI for the Proxy Server

◆ getConfig()

GuzzleHttp\Client::getConfig ( ?string $option = null)
inherited

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.

Parameters
string | null$optionThe config option to retrieve.
Return values
mixed
Deprecated
Client\getConfig will be removed in guzzlehttp/guzzle:8.0.

Implements GuzzleHttp\ClientInterface.

◆ request()

GuzzleHttp\Client::request ( string $method,
$uri = '',
array $options = [] )
inherited

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.

Parameters
string$methodHTTP method.
string | UriInterface$uriURI object or string.
array$optionsRequest options to apply. See GuzzleHttp\RequestOptions.
Exceptions
GuzzleException

Implements GuzzleHttp\ClientInterface.

◆ requestAsync()

GuzzleHttp\Client::requestAsync ( string $method,
$uri = '',
array $options = [] )
inherited

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.

Parameters
string$methodHTTP method
string | UriInterface$uriURI object or string.
array$optionsRequest options to apply. See GuzzleHttp\RequestOptions.

Implements GuzzleHttp\ClientInterface.

◆ send()

GuzzleHttp\Client::send ( RequestInterface $request,
array $options = [] )
inherited

Send an HTTP request.

Parameters
array$optionsRequest options to apply to the given request and to the transfer. See GuzzleHttp\RequestOptions.
Exceptions
GuzzleException

Implements GuzzleHttp\ClientInterface.

◆ sendAsync()

GuzzleHttp\Client::sendAsync ( RequestInterface $request,
array $options = [] )
inherited

Asynchronously send an HTTP request.

Parameters
array$optionsRequest options to apply to the given request and to the transfer. See GuzzleHttp\RequestOptions.

Implements GuzzleHttp\ClientInterface.

◆ sendRequest()

GuzzleHttp\Client::sendRequest ( RequestInterface $request)
inherited

The HttpClient PSR (PSR-18) specify this method.

@inheritDoc

Implements Psr\Http\Client\ClientInterface.

◆ setup_proxy()

core\http_client::setup_proxy ( array $settings)
protected

Get the proxy configuration.

See also
{https://docs.guzzlephp.org/en/stable/request-options.html#proxy}
Parameters
array$settingsThe incoming settings.
Return values
arrayThe proxy settings

The documentation for this class was generated from the following file: