示例#1
0
 /**
  * Create Account Command Handle
  *
  * Processes business logic for the account creation command.
  * @param  CreateAccount $command Command object.
  * @return AccountWasCreated      Event object.
  */
 protected function handleCreateAccount(CreateAccount $command)
 {
     $data = $command->getPayload();
     $account_id = new AccountId(Uuid::uuid4()->toString());
     $owner = new OwnerName($data->owner);
     $deposit = new UsDollar($data->deposit);
     if ($deposit->getValue() < self::MINIMUM_TO_OPEN) {
         throw new MinimumDepositException(sprintf('The deposit of $%s is under the required minimum of $%s', $deposit->getValue(), self::MINIMUM_TO_OPEN));
     }
     return new AccountWasCreated($account_id->getValue(), compact('owner', 'deposit'));
 }
示例#2
0
<?php

use RayEmitter\Example\BankAccount\CreateAccount;
use RayEmitter\Example\BankAccount\DepositMoney;
use RayEmitter\Example\BankAccount\GetAccountBalance;
use RayEmitter\Example\BankAccount\WithdrawMoney;
$data = ['owner' => 'Owner Name', 'deposit' => 64];
$command = new CreateAccount($data);
$command->run();
$account = '12345-45771...';
$data = ['deposit' => 10];
$command = new DepositMoney($account, $data, 0);
$command->run();
$data = ['withdrawl' => 306];
$command = new WithdrawMoney($account, $data, 1);
$command->setExpectedSequence(1)->run();
$query = new GetAccountBalance($account);
echo $query->run();
// As of sequence 1, return value should be 360.