Created
September 9, 2019 21:17
-
-
Save chrisharrison/894873b2aa9b886d437ffc5e94d4ae35 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class ProduceDocumentHandler | |
{ | |
private $accountFinder; | |
private $pdfGenerator; | |
public function __construct( | |
AccountFinder $accountFinder, | |
PdfGenerator $pdfGenerator | |
) { | |
$this->accountFinder = $accountFinder; | |
$this->pdfGenerator = $pdfGenerator; | |
} | |
public function handle(Command $command, string $templateName): void | |
{ | |
$account = $this->accountFinder->byId($command->accountId()); | |
$accountTotal = 0; | |
foreach ($account->items as $item) { | |
$accountTotal += $item->total(); | |
} | |
$this->pdfGenerator->generate($templateName, $account, $accountTotal); | |
} | |
} | |
final class ProduceAccountStatementHandler extends ProduceDocumentHandler | |
{ | |
public function handle(Command $command): void | |
{ | |
parent::handle($command, 'account-statement.template'); | |
} | |
} | |
final class ProducePaymentOverdueNoticeHandler extends ProduceDocumentHandler | |
{ | |
public function handle(Command $command): void | |
{ | |
parent::handle($command, 'payment-overdue-notice.template'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment