PHP Класс yii2tech\balance\Manager

См. также: ManagerInterface
С версии: 1.0
Автор: Paul Klimov ([email protected])
Наследование: extends yii\base\Component, implements yii2tech\balance\ManagerInterface
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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.

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

Метод Описание
decrease ( $account, $amount, $data = [] )
increase ( $account, $amount, $data = [] )
revert ( $transactionId, $data = [] )
transfer ( $from, $to, $amount, $data = [] )

Защищенные методы

Метод Описание
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.

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

afterCreateTransaction() защищенный Метод

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.
Результат array adjusted transaction data.

beforeCreateTransaction() защищенный Метод

This method is invoked before creating transaction.
protected beforeCreateTransaction ( mixed $accountId, array $data ) : array
$accountId mixed account ID.
$data array transaction data.
Результат array adjusted transaction data.

createAccount() абстрактный защищенный Метод

Creates new account with given attributes.
abstract protected createAccount ( array $attributes ) : mixed
$attributes array account attributes in format: attribute => value
Результат mixed created account ID.

createTransaction() абстрактный защищенный Метод

Writes transaction data into persistent storage.
abstract protected createTransaction ( array $attributes ) : mixed
$attributes array attributes associated with transaction in format: attribute => value
Результат mixed new transaction ID.

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

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

fetchAccountId() защищенный Метод

protected fetchAccountId ( mixed $idOrFilter ) : mixed
$idOrFilter mixed account ID or filter condition.
Результат mixed account ID.

findAccountId() абстрактный защищенный Метод

Finds account ID matching given filter attributes.
abstract protected findAccountId ( array $attributes ) : mixed | null
$attributes array filter attributes.
Результат mixed | null account ID, `null` - if not found.

findTransaction() абстрактный защищенный Метод

Finds transaction data by ID.
abstract protected findTransaction ( mixed $id ) : array | null
$id mixed transaction ID.
Результат array | null transaction data, `null` - if not found.

getDateAttributeValue() защищенный Метод

Returns actual now date value for the transaction.
protected getDateAttributeValue ( ) : mixed
Результат mixed date attribute value.

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

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

incrementAccountBalance() абстрактный защищенный Метод

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 revert ( $transactionId, $data = [] )

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

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

Описание свойств

$accountBalanceAttribute публичное свойство

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

$accountLinkAttribute публичное свойство

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

$amountAttribute публичное свойство

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

$autoCreateAccount публичное свойство

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

$dateAttribute публичное свойство

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

$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.
public $dateAttributeValue

$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.
public $extraAccountLinkAttribute