Skip to content

Instantly share code, notes, and snippets.

@ralder
Last active August 21, 2020 11:50
Show Gist options
  • Save ralder/9ab0052c7f406a8511e007895dbc0aa8 to your computer and use it in GitHub Desktop.
Save ralder/9ab0052c7f406a8511e007895dbc0aa8 to your computer and use it in GitHub Desktop.
<?php
interface BalanceAccountTypeParamsAware
{
/** @return AbstractTypeParameter[] */
public function getTypeParams(): array;
}
class BalanceAccountType implemements BalanceAccountTypeParamsAware
{
public function __construct(CurrencyParamType $currencyParamType, PayableParamType $payableParamType)
{...}
public function getTypeParams(): array
{
return [$this->currencyParamType, $this->payableParamType];
}
}
class CustomBalanceAccountTypeParams implements BalanceAccountTypeParamsAware
{...}
class BalanceAccountTypeCriteria
{
public function __construct(BalanceAccountTypeParamsAware $typeParams)
{...}
public function get()
{
$params = $this->typeParams->getTypeParams();
...
}
}
// и тогда вызывать можно либо с кастомным набором параметров либо с жестким типом
// 1
$typeParams = new CustomBalanceAccountTypeParams([
CurrencyTypeParams::create('RUB'),
]);
$criteria = new BalanceAccountTypeCriteria($typeParams);
// 2
$typeParams = new BalanceAccountType(
CurrencyTypeParams::create('RUB'),
PayableTypeParams::create('bonus')
);
$criteria = new BalanceAccountTypeCriteria($typeParams);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment