Skip to content

Instantly share code, notes, and snippets.

@chrisharrison
Created September 9, 2019 21:17
Show Gist options
  • Save chrisharrison/894873b2aa9b886d437ffc5e94d4ae35 to your computer and use it in GitHub Desktop.
Save chrisharrison/894873b2aa9b886d437ffc5e94d4ae35 to your computer and use it in GitHub Desktop.
<?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