From 576d34e9bbc3cdc21793668b1f4a7f10fe465713 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 15 Apr 2020 10:23:46 +0300 Subject: [PATCH] htmlizer factory --- application/Espo/Core/Htmlizer/Factory.php | 57 +++++++++++++++++++ application/Espo/Core/Htmlizer/Htmlizer.php | 2 +- .../Espo/Core/Loaders/HtmlizerFactory.php | 40 +++++++++++++ application/Espo/Services/Pdf.php | 22 +------ 4 files changed, 101 insertions(+), 20 deletions(-) create mode 100644 application/Espo/Core/Htmlizer/Factory.php create mode 100644 application/Espo/Core/Loaders/HtmlizerFactory.php diff --git a/application/Espo/Core/Htmlizer/Factory.php b/application/Espo/Core/Htmlizer/Factory.php new file mode 100644 index 0000000000..5429661edd --- /dev/null +++ b/application/Espo/Core/Htmlizer/Factory.php @@ -0,0 +1,57 @@ +container = $container; + } + + public function create(bool $skipAcl = false) + { + return new Htmlizer( + $this->container->get('fileManager'), + $this->container->get('dateTime'), + $this->container->get('number'), + !$skipAcl ? $this->container->get('acl') : null, + $this->container->get('entityManager'), + $this->container->get('metadata'), + $this->container->get('defaultLanguage'), + $this->container->get('config'), + $this->container->get('serviceFactory') + ); + } +} diff --git a/application/Espo/Core/Htmlizer/Htmlizer.php b/application/Espo/Core/Htmlizer/Htmlizer.php index f4a3b4d934..c6dc4bd817 100644 --- a/application/Espo/Core/Htmlizer/Htmlizer.php +++ b/application/Espo/Core/Htmlizer/Htmlizer.php @@ -39,7 +39,7 @@ use Espo\Core\Utils\Config; use Espo\Core\Utils\Language; use Espo\Core\Utils\Metadata; use Espo\ORM\EntityManager; -use Espo\Core\serviceFactory; +use Espo\Core\ServiceFactory; use LightnCandy\LightnCandy as LightnCandy; diff --git a/application/Espo/Core/Loaders/HtmlizerFactory.php b/application/Espo/Core/Loaders/HtmlizerFactory.php new file mode 100644 index 0000000000..3e80d03e98 --- /dev/null +++ b/application/Espo/Core/Loaders/HtmlizerFactory.php @@ -0,0 +1,40 @@ +getContainer() + ); + } +} diff --git a/application/Espo/Services/Pdf.php b/application/Espo/Services/Pdf.php index ec07f550f2..ffb1c7cb76 100644 --- a/application/Espo/Services/Pdf.php +++ b/application/Espo/Services/Pdf.php @@ -47,14 +47,13 @@ class Pdf extends \Espo\Core\Services\Base protected function init() { - $this->addDependency('fileManager'); $this->addDependency('acl'); $this->addDependency('metadata'); $this->addDependency('serviceFactory'); - $this->addDependency('dateTime'); - $this->addDependency('number'); $this->addDependency('entityManager'); $this->addDependency('defaultLanguage'); + + $this->addDependency('htmlizerFactory'); } protected function getAcl() @@ -72,11 +71,6 @@ class Pdf extends \Espo\Core\Services\Base return $this->getInjection('serviceFactory'); } - protected function getFileManager() - { - return $this->getInjection('fileManager'); - } - protected function printEntity(Entity $entity, Entity $template, Htmlizer $htmlizer, \Espo\Core\Pdf\Tcpdf $pdf, ?array $additionalData = null) { @@ -308,16 +302,6 @@ class Pdf extends \Espo\Core\Services\Base protected function createHtmlizer() { - return new Htmlizer( - $this->getFileManager(), - $this->getInjection('dateTime'), - $this->getInjection('number'), - $this->getAcl(), - $this->getInjection('entityManager'), - $this->getInjection('metadata'), - $this->getInjection('defaultLanguage'), - $this->getInjection('config'), - $this->getInjection('serviceFactory') - ); + return $this->getInjection('htmlizerFactory')->create(); } }