PHP Class yii2tech\balance\Manager

See also: ManagerInterface
Since: 1.0
Author: Paul Klimov ([email protected])
Inheritance: extends yii\base\Component, implements yii2tech\balance\ManagerInterface
Afficher le fichier Open project: yii2tech/balance Class Usage Examples

Méthodes publiques

Свойство Type Description
$accountBalanceAttribute name of the account entity attribute, which should store current balance value.
$accountLinkAttribute name of the transaction entity attribute, which should be used to link transaction entity with account entity (store associated account ID).
$amountAttribute name of the transaction entity attribute, which should store amount.
$autoCreateAccount whether to automatically create requested account, if it does not yet exist.
$dateAttribute name of the transaction entity attribute, which should store date.
$dateAttributeValue value which should be used for new transaction date composition. This can be plain value, object like [[\yii\db\Expression]] or a PHP callback, which returns it. If not set PHP time() function will be used.
$extraAccountLinkAttribute name of the transaction entity attribute, which should store additional affected account ID. This attribute will be filled only at transfer() method execution and will store ID of the account transferred from or to, depending on the context. If not set, no information about the extra account context will be saved. Note: absence of this field will affect logic of some methods like Manager::revert.

Méthodes publiques

Méthode Description
decrease ( $account, $amount, $data = [] )
increase ( $account, $amount, $data = [] )
revert ( $transactionId, $data = [] )
transfer ( $from, $to, $amount, $data = [] )

Méthodes protégées

Méthode Description
afterCreateTransaction ( mixed $transactionId, mixed $accountId, array $data ) : array This method is invoked after transaction has been created.
beforeCreateTransaction ( mixed $accountId, array $data ) : array This method is invoked before creating transaction.
createAccount ( array $attributes ) : mixed Creates new account with given attributes.
createTransaction ( array $attributes ) : mixed Writes transaction data into persistent storage.
fetchAccountId ( mixed $idOrFilter ) : mixed
findAccountId ( array $attributes ) : mixed | null Finds account ID matching given filter attributes.
findTransaction ( mixed $id ) : array | null Finds transaction data by ID.
getDateAttributeValue ( ) : mixed Returns actual now date value for the transaction.
incrementAccountBalance ( mixed $accountId, integer | float $amount ) Increases current account balance value.

Method Details

afterCreateTransaction() protected méthode

This method is invoked after transaction has been created.
protected afterCreateTransaction ( mixed $transactionId, mixed $accountId, array $data ) : array
$transactionId mixed transaction ID.
$accountId mixed account ID.
$data array transaction data.
Résultat array adjusted transaction data.

beforeCreateTransaction() protected méthode

This method is invoked before creating transaction.
protected beforeCreateTransaction ( mixed $accountId, array $data ) : array
$accountId mixed account ID.
$data array transaction data.
Résultat array adjusted transaction data.

createAccount() abstract protected méthode

Creates new account with given attributes.
abstract protected createAccount ( array $attributes ) : mixed
$attributes array account attributes in format: attribute => value
Résultat mixed created account ID.

createTransaction() abstract protected méthode

Writes transaction data into persistent storage.
abstract protected createTransaction ( array $attributes ) : mixed
$attributes array attributes associated with transaction in format: attribute => value
Résultat mixed new transaction ID.

decrease() public méthode

public decrease ( $account, $amount, $data = [] )

fetchAccountId() protected méthode

protected fetchAccountId ( mixed $idOrFilter ) : mixed
$idOrFilter mixed account ID or filter condition.
Résultat mixed account ID.

findAccountId() abstract protected méthode

Finds account ID matching given filter attributes.
abstract protected findAccountId ( array $attributes ) : mixed | null
$attributes array filter attributes.
Résultat mixed | null account ID, `null` - if not found.

findTransaction() abstract protected méthode

Finds transaction data by ID.
abstract protected findTransaction ( mixed $id ) : array | null
$id mixed transaction ID.
Résultat array | null transaction data, `null` - if not found.

getDateAttributeValue() protected méthode

Returns actual now date value for the transaction.
protected getDateAttributeValue ( ) : mixed
Résultat mixed date attribute value.

increase() public méthode

public increase ( $account, $amount, $data = [] )

incrementAccountBalance() abstract protected méthode

Increases current account balance value.
abstract protected incrementAccountBalance ( mixed $accountId, integer | float $amount )
$accountId mixed account ID.
$amount integer | float amount to be added to the current balance.

revert() public méthode

public revert ( $transactionId, $data = [] )

transfer() public méthode

public transfer ( $from, $to, $amount, $data = [] )

Property Details

$accountBalanceAttribute public_oe property

name of the account entity attribute, which should store current balance value.
public $accountBalanceAttribute

$accountLinkAttribute public_oe property

name of the transaction entity attribute, which should be used to link transaction entity with account entity (store associated account ID).
public $accountLinkAttribute

$amountAttribute public_oe property

name of the transaction entity attribute, which should store amount.
public $amountAttribute

$autoCreateAccount public_oe property

whether to automatically create requested account, if it does not yet exist.
public $autoCreateAccount

$dateAttribute public_oe property

name of the transaction entity attribute, which should store date.
public $dateAttribute

$dateAttributeValue public_oe property

value which should be used for new transaction date composition. This can be plain value, object like [[\yii\db\Expression]] or a PHP callback, which returns it. If not set PHP time() function will be used.
public $dateAttributeValue

$extraAccountLinkAttribute public_oe property

name of the transaction entity attribute, which should store additional affected account ID. This attribute will be filled only at transfer() method execution and will store ID of the account transferred from or to, depending on the context. If not set, no information about the extra account context will be saved. Note: absence of this field will affect logic of some methods like Manager::revert.
public $extraAccountLinkAttribute