PortaBilling API

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:

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
throws
PortaAuthException
Return values
mixed

getAccount()

Provides account record or throw PortaAuthException if there no record inside.

public getAccount() : array<string|int, mixed>
Tags
inherit
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
inherit
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
inherit
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
inherit
Return values
CacheInterface

getCacheTag()

Return cache tag to use for session storage object in the cache

public getCacheTag() : string
Tags
inherit
Return values
string

getSessionRefreshMargin()

Returns margin to token expire time triggering token refresh procedure.

public getSessionRefreshMargin() : int
Tags
inherit
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
inherit
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
inherit
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
inherit
Return values
self

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
inherit
Return values
self

for chaining

Search results