Skip to content

Instantly share code, notes, and snippets.

@chrisharrison
Created August 31, 2019 11:18
Show Gist options
  • Save chrisharrison/d78164648babdb530d7928179e2d9582 to your computer and use it in GitHub Desktop.
Save chrisharrison/d78164648babdb530d7928179e2d9582 to your computer and use it in GitHub Desktop.
abstract class ProducePdfHandler
{
private $pdfGenerator;
private $dataProvider;
public function __construct(
PdfGenerator $pdfGenerator,
DefaultDataProvider $dataProvider
) {
$this->pdfGenerator = $pdfGenerator;
$this->dataProvider = $dataProvider;
}
abstract public function invoke(Comamnd $command): PdfId;
private function produce(Command $command, PdfTemplate $template): PdfId
{
$data = $this->dataProvider->provide($command->accountId());
$id = $this->pdfGenerator->generate($template, $data);
return $id;
}
}
final class ProduceStatementOfAccountHandler extends ProducePdfHandler
{
public function invoke(Comamnd $command): PdfId
{
return $this->produce(PdfTemplate::STATEMENT_OF_ACCOUNT);
}
}
final class ProducePaymentOverdueHandler extends ProducePdfHandler
{
public function invoke(Comamnd $command): PdfId
{
return $this->produce(PdfTemplate::PAYMENT_OVERDUE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment