Created
April 15, 2018 11:22
-
-
Save shin1x1/1848b5c376493f7a005031fbce97c648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Acme\Account\UseCases; | |
use Acme\Account\Models\Account; | |
use Acme\Account\Models\AccountNumber; | |
use Acme\Account\Models\Money; | |
final class TransferMoney | |
{ | |
/** @var TransferMoneyQueryPort */ | |
private $query; | |
/** @var TransferMoneyStorePort */ | |
private $store; | |
public function __construct(TransferMoneyQueryPort $query, TransferMoneyStorePort $store) | |
{ | |
$this->query = $query; | |
$this->store = $store; | |
} | |
public function execute( | |
AccountNumber $sourceNumber, | |
AccountNumber $destinationNumber, | |
Money $money | |
) { | |
$source = $this->query->source($sourceNumber); | |
$destination = $this->query->destination($destinationNumber); | |
$source->withdraw($money); | |
$destination->deposit($money); | |
$this->store->store($source, $destination); | |
} | |
} | |
interface TransferMoneyQueryPort | |
{ | |
public function source(AccountNumber $accountNumber): Account; | |
public function destination(AccountNumber $accountNumber): Account; | |
} | |
interface TransferMoneyStorePort | |
{ | |
public function store(Account $source, Account $destination); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment