Last active
December 23, 2018 12:00
-
-
Save l3l0/edcc9b84aed8ece61e0bbce8d6b2d0a4 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 | |
| declare(strict_types=1); | |
| class AddressDepartamentContentQuery implements ContentQuery | |
| { | |
| private $addressRepository; | |
| private $departamentRepository; | |
| public function __consturct(AddressRepository $addressRepository, DepartamentRepository $departamentRepository) | |
| { | |
| $this->addressRepository = $addressRepository; | |
| $this->departamentRepository = $departamentRepository; | |
| } | |
| public function fetch(): array | |
| { | |
| $addresses = $this->addressRepository->findAll(); | |
| $departments = $this->departmentRepository->findAll(); | |
| $pdfInformation = []; | |
| foreach ($addresses as $i => $address) { | |
| if ($address->withDepartments()) { | |
| $pdfInformation[$i]['address'] = $address->getFullAddress(); | |
| $pdfInformation[$i]['person'] = $address->getPerson(); | |
| } else { | |
| foreach ($departments as $department) { | |
| $pdfInformation[$i][$department->getName()]['address'] = $address->getFullAddress(); | |
| if ($address->getPerson()) { | |
| $pdfInformation[$i][$department->getName()]['person'] = $address->getPerson(); | |
| } else { | |
| $pdfInformation[$i][$department->getName()]['contact'] = $this->sanitize($address->getContact()); | |
| } | |
| } | |
| } | |
| } | |
| return $pdfInformation; | |
| } | |
| } |
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 | |
| interface ContentQuery | |
| { | |
| public function fetch(): array; | |
| } |
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 | |
| declare(strict_types=1); | |
| final class FPDFWriter implements PDFWriter | |
| { | |
| private $pdf; | |
| private $webFolder; | |
| public function __construct(FPDF $fpdf, string $webFolder) | |
| { | |
| $this->pdf = $fpdf; | |
| $this->webFolder = $webFolder; | |
| } | |
| public function writer(array $content): void | |
| { | |
| $pdf = $this->fpdf->generate($content); | |
| file_put_contents($this->webFolder . $pdf->getUri()); | |
| } | |
| } |
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 | |
| declare(strict_types=1); | |
| class PDFGenerator | |
| { | |
| private $contentQuery; | |
| private $pdfWriter; | |
| public function __construct(PDFContentQuery $contentQuery, PDFWriter $writer) | |
| { | |
| $this->contentQuery = $contentQuery; | |
| $this->pdfWriter = $writer; | |
| } | |
| public function execute(): void | |
| { | |
| $this->pdfWriter->write($this->contentQuery->fetch()); | |
| } | |
| } |
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 | |
| interface PDFWriter | |
| { | |
| public function write(array $content): void; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment