Skip to content

Instantly share code, notes, and snippets.

@chrisharrison
Created September 9, 2019 21:11
Show Gist options
  • Save chrisharrison/a52a0e3d8208512601f82ccbb4191523 to your computer and use it in GitHub Desktop.
Save chrisharrison/a52a0e3d8208512601f82ccbb4191523 to your computer and use it in GitHub Desktop.
<?php
final class ProduceAccountStatementHandler
{
private $accountFinder;
private $pdfGenerator;
public function __construct(
AccountFinder $accountFinder,
PdfGenerator $pdfGenerator
) {
$this->accountFinder = $accountFinder;
$this->pdfGenerator = $pdfGenerator;
}
public function handle(Command $command): void
{
$account = $this->accountFinder->byId($command->accountId());
$accountTotal = 0;
foreach ($account->items as $item) {
$accountTotal += $item->total();
}
$this->pdfGenerator->generate('account-statement.template', $account, $accountTotal);
}
}
final class ProducePaymentOverdueNoticeHandler
{
private $accountFinder;
private $pdfGenerator;
public function __construct(
AccountFinder $accountFinder,
PdfGenerator $pdfGenerator
) {
$this->accountFinder = $accountFinder;
$this->pdfGenerator = $pdfGenerator;
}
public function handle(Command $command): void
{
$account = $this->accountFinder->byId($command->accountId());
$accountTotal = 0;
foreach ($account->items as $item) {
$accountTotal += $item->total();
}
$this->pdfGenerator->generate('payment-overdue-notice.template', $account, $accountTotal);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment