Created
August 31, 2019 11:18
-
-
Save chrisharrison/d78164648babdb530d7928179e2d9582 to your computer and use it in GitHub Desktop.
This file contains 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
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