From 69c5ac724e913c1aba2fa2f6fd15c9ec8e445a08 Mon Sep 17 00:00:00 2001 From: Torben Hansen Date: Wed, 15 Dec 2021 10:30:42 +0100 Subject: [PATCH] [TASK] Avoid objectManager usage in PdfView class --- Classes/View/PdfView.php | 53 +++++++++++++--------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/Classes/View/PdfView.php b/Classes/View/PdfView.php index 94868bf..d9d3ae9 100644 --- a/Classes/View/PdfView.php +++ b/Classes/View/PdfView.php @@ -1,8 +1,9 @@ + * (C) Mittwald CM Service GmbH & Co. KG * * All rights reserved * @@ -21,7 +22,7 @@ * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! - * ************************************************************* */ + ***************************************************************/ namespace Mittwald\Web2pdf\View; @@ -32,17 +33,8 @@ use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Fluid\View\StandaloneView; - -/** - * PDFView - * - * @author Kevin Purrmann , Purrmann Websolutions - * @package Mittwald - * @subpackage Web2Pdf\View - */ class PdfView { @@ -64,11 +56,6 @@ class PdfView */ protected $pdfLinkUtility; - /** - * @var ObjectManagerInterface - */ - protected $objectManager; - /** * PdfView constructor. * @param ModuleOptions $options @@ -78,13 +65,11 @@ class PdfView public function __construct( ModuleOptions $options, FilenameUtility $fileNameUtility, - PdfLinkUtility $pdfLinkUtility, - ObjectManagerInterface $objectManager + PdfLinkUtility $pdfLinkUtility ) { $this->options = $options; $this->fileNameUtility = $fileNameUtility; $this->pdfLinkUtility = $pdfLinkUtility; - $this->objectManager = $objectManager; } @@ -160,20 +145,17 @@ protected function getPdfObject(): Mpdf $topMargin = ($this->options->getPdfTopMargin()) ? $this->options->getPdfTopMargin() : '15'; $styleSheet = ($this->options->getPdfStyleSheet()) ? $this->options->getPdfStyleSheet() : 'print'; - /* @var $pdf Mpdf */ - $pdf = $this->objectManager->get( - Mpdf::class, [ - 'format' => $pageFormat, - 'default_font_size' => 12, - 'margin_left' => $leftMargin, - 'margin_right' => $rightMargin, - 'margin_top' => $topMargin, - 'margin_bottom' => $bottomMargin, - 'orientation' => $pageOrientation, - 'tempDir' => Environment::getVarPath() . '/web2pdf', - 'fontDir' => ExtensionManagementUtility::extPath('web2pdf') . 'Resources/Public/Fonts', - ] - ); + $pdf = new Mpdf([ + 'format' => $pageFormat, + 'default_font_size' => 12, + 'margin_left' => $leftMargin, + 'margin_right' => $rightMargin, + 'margin_top' => $topMargin, + 'margin_bottom' => $bottomMargin, + 'orientation' => $pageOrientation, + 'tempDir' => Environment::getVarPath() . '/web2pdf', + 'fontDir' => ExtensionManagementUtility::extPath('web2pdf') . 'Resources/Public/Fonts', + ]); $pdf->SetMargins($leftMargin, $rightMargin, $topMargin); @@ -190,8 +172,7 @@ protected function getPdfObject(): Mpdf */ protected function getPartial($templateName, $arguments = array()): string { - /* @var $partial \TYPO3\CMS\Fluid\View\StandaloneView */ - $partial = $this->objectManager->get(StandaloneView::class); + $partial = GeneralUtility::makeInstance(StandaloneView::class); $partial->setLayoutRootPaths($this->options->getLayoutRootPaths()); $partial->setPartialRootPaths($this->options->getPartialRootPaths()); $partial->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(end($partial->getPartialRootPaths())) . 'Pdf/' . ucfirst($templateName) . '.html');