PHP Class Snorlax\RestClient

Works as a know it all class that keeps the client and the resources together.
Show file Open project: ezdeliveryco/snorlax

Public Methods

Method Description
__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

Private Methods

Method Description
createDefaultClient ( array $params ) : Client Creates a new default client based on the given parameters

Method Details

__construct() public method

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

__get() public method

Allows us to use $client->resource so we don't need to call $client->getResource($resource) every time
public __get ( $resource ) : Snorlax\Resource
$resource
return Snorlax\Resource

addResources() public method

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

getOriginalClient() public method

Returns the internal client
public getOriginalClient ( ) : GuzzleHttp\ClientInterface
return GuzzleHttp\ClientInterface

getResource() public method

Instantiates and returns the asked resource.
public getResource ( string $resource ) : Snorlax\Resource
$resource string The resource name
return Snorlax\Resource The instantiated resource

request() public method

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.
return Psr\Http\Message\ResponseInterface

setAuthorization() public method

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() public method

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