Config
in package
implements
ConfigInterface
Porta-API general configuration class which may extend for extra features
It works as lib-specific container, providing every part of the library with required data and environment bindings.
Should be a good for container autowiring. All dependencies are bound to interfaces, allowing to use implementatnon of your choice, but you need to hint $host and $account
Require:
- PSR-17 RequestFactoryInterface to created PSR-7 requests
- PSR-17 StreamFactoryInterface to create PSR-7 streams
- PSR-16 CacheInterface (simple cache) to allow session data (tocken) persist across script calls. Simple implementation of file cache FileCache and one-time memory only stub InstanceCache packaged.
- (@see ClientAdapterInterface} - propertary interface, this allow to use almost any HTTP client library or build your own HTTP client backend. PSR-18 client adapter packaged Psr18Adapter.
Interfaces, Classes, Traits and Enums
- ConfigInterface
- Interface to manage billing server API cinfiguration
Table of Contents
- __construct() : mixed
- Setup configuration object
- getAccount() : array<string|int, mixed>
- Provides account record or throw PortaAuthException if there no record inside.
- getBaseApiRequest() : RequestInterface
- Returns base API psr-7 request object with base path + given path
- getBaseEspfRequest() : RequestInterface
- Returns base ESPF psr-7 request of given type with base path + given path
- getCache() : CacheInterface
- Returns PSR-16 caching object to store persistent session data
- getCacheTag() : string
- Return cache tag to use for session storage object in the cache
- getClientAdaptor() : ClientAdapterInterface
- Returns ClientAdaptor for currently configured client
- getSessionRefreshMargin() : int
- Returns margin to token expire time triggering token refresh procedure.
- getStream() : StreamInterface
- Returns psr-7 Stream object created with given string
- hasAccount() : bool
- Returns true if accound record present in the config and it's correct.
- setAccount() : self
- Sets account record. Exception if the record is inconsistent
- setCacheTag() : ClientAdapterInterface
- Sets cache tag to use for session storage object in the cache
- setSessionRefreshMargin() : self
- Set margin to token expire time triggering token refresh procedure.
Methods
__construct()
Setup configuration object
public
__construct(string $host, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory, ClientAdapterInterface $clientAdaptor, CacheInterface $cache[, array<string|int, mixed>|null $account = null ]) : mixed
Parameters
- $host : string
-
Hostname/IP address of the server, no slashes, no schema, but port if required. Example:
bill-sip.mycompany.com
- $requestFactory : RequestFactoryInterface
-
PSR-17 Factory to create requests
- $streamFactory : StreamFactoryInterface
-
PSR-17 Factory to create steams
- $clientAdaptor : ClientAdapterInterface
-
Client adaptor to use.
- $cache : CacheInterface
-
PSR-16 Simple cache object to persist session data
- $account : array<string|int, mixed>|null = null
-
Account record to login to the billing. Combination of login+password or login+token required
$account = [ 'login' => 'myUserName', // Mandatory username 'password' => 'myPassword', // When login with password 'token' => 'myToken' // When login with API token
Tags
Return values
mixed —getAccount()
Provides account record or throw PortaAuthException if there no record inside.
public
getAccount() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —must have a pair of keys: account
+password
or account
+token
getBaseApiRequest()
Returns base API psr-7 request object with base path + given path
public
getBaseApiRequest([string $path = '' ]) : RequestInterface
Parameters
- $path : string = ''
-
extra path to append after API prefix path
Tags
Return values
RequestInterface —base Request object, filled with URI
getBaseEspfRequest()
Returns base ESPF psr-7 request of given type with base path + given path
public
getBaseEspfRequest(string $method[, string $path = '' ]) : RequestInterface
Parameters
- $method : string
-
request method to use
- $path : string = ''
-
extra path to append after API prefix path
Tags
Return values
RequestInterface —Base Request object of given type, filled with URI
getCache()
Returns PSR-16 caching object to store persistent session data
public
getCache() : CacheInterface
Tags
Return values
CacheInterface —getCacheTag()
Return cache tag to use for session storage object in the cache
public
getCacheTag() : string
Tags
Return values
string —getClientAdaptor()
Returns ClientAdaptor for currently configured client
public
getClientAdaptor() : ClientAdapterInterface
Tags
Return values
ClientAdapterInterface —getSessionRefreshMargin()
Returns margin to token expire time triggering token refresh procedure.
public
getSessionRefreshMargin() : int
Tags
Return values
int —seconds before token expire time to trigger refresh
getStream()
Returns psr-7 Stream object created with given string
public
getStream([string $content = '' ]) : StreamInterface
Parameters
- $content : string = ''
-
conten of the Stream
Tags
Return values
StreamInterface —Stream object, filled with content
hasAccount()
Returns true if accound record present in the config and it's correct.
public
hasAccount() : bool
Tags
Return values
bool —setAccount()
Sets account record. Exception if the record is inconsistent
public
setAccount([array<string|int, mixed>|null $account = null ]) : self
Parameters
- $account : array<string|int, mixed>|null = null
-
must have a pair of keys: 'account'+'password' or 'account'+'token', null to clear account record out.
Tags
Return values
self —for chaining
setCacheTag()
Sets cache tag to use for session storage object in the cache
public
setCacheTag(string $tag) : ClientAdapterInterface
Parameters
- $tag : string
Tags
Return values
ClientAdapterInterface —self mutable object for chaining
setSessionRefreshMargin()
Set margin to token expire time triggering token refresh procedure.
public
setSessionRefreshMargin(int $margin) : self
Parameters
- $margin : int
-
token refresh margin in seconds
Tags
Return values
self —for chaining