PHP Класс Snorlax\RestClient

Works as a know it all class that keeps the client and the resources together.
Показать файл Открыть проект

Открытые методы

Метод Описание
__construct ( array $config ) Initializes configuration parameters and resources
__get ( $resource ) : Snorlax\Resource Allows us to use $client->resource so we don't need to call $client->getResource($resource) every time
addResources ( array $resources ) Appends the given resources to the ones already being used
getOriginalClient ( ) : GuzzleHttp\ClientInterface Returns the internal client
getResource ( string $resource ) : Snorlax\Resource Instantiates and returns the asked resource.
request ( string $method, string | Psr\Http\Message\UriInterface $uri, array $options = [] ) : Psr\Http\Message\ResponseInterface
setAuthorization ( Snorlax\Auth\Authorization $auth ) Changes the authentication method on all the requests made by this client
setClient ( array $config ) Sets the client according to the given $config array, following the rules: - If no custom client is given, instantiates a new GuzzleHttp\Client - If an instance of GuzzleHttp\ClientInterface is given, we only pass it through - If a closure is given, it gets executed receiving the parameters given

Приватные методы

Метод Описание
createDefaultClient ( array $params ) : Client Creates a new default client based on the given parameters

Описание методов

__construct() публичный Метод

Initializes configuration parameters and resources
public __construct ( array $config )
$config array

__get() публичный Метод

Allows us to use $client->resource so we don't need to call $client->getResource($resource) every time
public __get ( $resource ) : Snorlax\Resource
$resource
Результат Snorlax\Resource

addResources() публичный Метод

Appends the given resources to the ones already being used
public addResources ( array $resources )
$resources array

getOriginalClient() публичный Метод

Returns the internal client
public getOriginalClient ( ) : GuzzleHttp\ClientInterface
Результат GuzzleHttp\ClientInterface

getResource() публичный Метод

Instantiates and returns the asked resource.
public getResource ( string $resource ) : Snorlax\Resource
$resource string The resource name
Результат Snorlax\Resource The instantiated resource

request() публичный Метод

public request ( string $method, string | Psr\Http\Message\UriInterface $uri, array $options = [] ) : Psr\Http\Message\ResponseInterface
$method string HTTP method.
$uri string | Psr\Http\Message\UriInterface URI object or string.
$options array Request options to apply.
Результат Psr\Http\Message\ResponseInterface

setAuthorization() публичный Метод

Changes the authentication method on all the requests made by this client
public setAuthorization ( Snorlax\Auth\Authorization $auth )
$auth Snorlax\Auth\Authorization The authorizaztion method

setClient() публичный Метод

Sets the client according to the given $config array, following the rules: - If no custom client is given, instantiates a new GuzzleHttp\Client - If an instance of GuzzleHttp\ClientInterface is given, we only pass it through - If a closure is given, it gets executed receiving the parameters given
public setClient ( array $config )
$config array