From 2e3179d83e6818597ff1bfabdd0c04ab70aec421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 29 Jul 2020 13:37:05 +0200 Subject: [PATCH] Extract variables from the HtmlEngine --- app/Services/PdfMaker/PdfMakerUtilities.php | 3 +- app/Utils/HtmlEngine.php | 8 ++--- .../PdfMaker/ExampleIntegrationTest.php | 36 +++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 tests/Feature/PdfMaker/ExampleIntegrationTest.php diff --git a/app/Services/PdfMaker/PdfMakerUtilities.php b/app/Services/PdfMaker/PdfMakerUtilities.php index 174caec83fe9..56e57be52d0f 100644 --- a/app/Services/PdfMaker/PdfMakerUtilities.php +++ b/app/Services/PdfMaker/PdfMakerUtilities.php @@ -116,7 +116,8 @@ trait PdfMakerUtilities public function updateVariables(array $variables) { - $html = strtr($this->getCompiledHTML(), $variables); + $html = strtr($this->getCompiledHTML(), $variables['labels']); + $html = strtr($this->getCompiledHTML(), $variables['values']); $this->document->loadHTML($html); diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index fc922bc5f3cd..677f98137472 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -29,18 +29,14 @@ class HtmlEngine public $company; - public $designer; - public $settings; public $entity_calc; public $entity_string; - public function __construct(Designer $designer, $invitation, $entity_string) + public function __construct($invitation, $entity_string) { - $this->designer = $designer; - $this->invitation = $invitation; $this->entity = $invitation->{$entity_string}; @@ -347,7 +343,7 @@ class HtmlEngine return $data; } - private function generateLabelsAndValues() + public function generateLabelsAndValues() { $data = []; diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php new file mode 100644 index 000000000000..78096a7bf95a --- /dev/null +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -0,0 +1,36 @@ +invitations()->first(); + + $engine = new HtmlEngine($invitation, 'invoice'); + + $state = [ + 'template' => [ + + ], + 'variables' => $engine->generateLabelsAndValues(), + ]; + + $maker = new PdfMaker($state); + + $maker + ->design(Plain::class) + ->build(); + + info($state); + info($maker->getCompiledHTML()); + } +}