From ff1e07ca42ec7567d0c69ea06ca8ce44e863364a Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Tue, 9 Apr 2024 13:27:06 +0200 Subject: [PATCH] CLEANUP: Make Rootline class a factory --- .../ResponsiveImagesProcessor.php | 7 ++- .../Factory/RootlineFactory.php} | 44 ++++++++++--------- Configuration/Services.yaml | 4 -- 3 files changed, 27 insertions(+), 28 deletions(-) rename Classes/{Sizes/Rootline.php => Domain/Factory/RootlineFactory.php} (78%) diff --git a/Classes/DataProcessing/ResponsiveImagesProcessor.php b/Classes/DataProcessing/ResponsiveImagesProcessor.php index 1d90bde..8b90e3b 100644 --- a/Classes/DataProcessing/ResponsiveImagesProcessor.php +++ b/Classes/DataProcessing/ResponsiveImagesProcessor.php @@ -24,9 +24,8 @@ */ use Codappix\ResponsiveImages\Configuration\ConfigurationManager; -use Codappix\ResponsiveImages\Domain\Repository\ContainerRepository; +use Codappix\ResponsiveImages\Domain\Factory\RootlineFactory; use Codappix\ResponsiveImages\Sizes\Breakpoint; -use Codappix\ResponsiveImages\Sizes\Rootline; use TYPO3\CMS\Core\Resource\FileInterface; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; @@ -44,7 +43,7 @@ final class ResponsiveImagesProcessor implements DataProcessorInterface public function __construct( private ConfigurationManager $configurationManager, - private ContainerRepository $containerRepository + private RootlineFactory $rootlineFactory ) { } @@ -75,7 +74,7 @@ public function process( return $processedData; } - $this->contentElementSizes = (new Rootline($this->containerRepository, $processedData['data'], $fieldName))->getFinalSizes(); + $this->contentElementSizes = $this->rootlineFactory->getFinalSizes($processedData['data'], $fieldName); $this->calculateFileDimensions(); $targetFieldName = (string) $cObj->stdWrapValue( diff --git a/Classes/Sizes/Rootline.php b/Classes/Domain/Factory/RootlineFactory.php similarity index 78% rename from Classes/Sizes/Rootline.php rename to Classes/Domain/Factory/RootlineFactory.php index 7aaf151..d093368 100644 --- a/Classes/Sizes/Rootline.php +++ b/Classes/Domain/Factory/RootlineFactory.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Codappix\ResponsiveImages\Sizes; +namespace Codappix\ResponsiveImages\Domain\Factory; /* * Copyright (C) 2024 Justus Moroni @@ -26,41 +26,44 @@ use B13\Container\Tca\Registry; use Codappix\ResponsiveImages\Domain\Repository\ContainerRepository; +use Codappix\ResponsiveImages\Sizes\BackendLayout; +use Codappix\ResponsiveImages\Sizes\BackendLayoutColumn; +use Codappix\ResponsiveImages\Sizes\Container; +use Codappix\ResponsiveImages\Sizes\ContainerColumn; +use Codappix\ResponsiveImages\Sizes\ContentElement; +use Codappix\ResponsiveImages\Sizes\ContentElementInterface; use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Page\PageLayoutResolver; -final class Rootline +final class RootlineFactory { - private readonly ContentElementInterface $contentElement; - private BackendLayout $backendLayout; - private array $finalSizes = []; - private string $fieldName; private string $backendLayoutIdentifier; public function __construct( - private ContainerRepository $containerRepository, + private readonly ContainerRepository $containerRepository, + private readonly PageLayoutResolver $pageLayoutResolver + ) { + } + + public function getFinalSizes( array $data, string $fieldName - ) { + ): array { $this->determineBackendLayout(); + $this->fieldName = $fieldName; - $this->contentElement = $this->determineContentElement(null, $data); + $contentElement = $this->determineContentElement(null, $data); - $this->determineRootline($this->contentElement); + $this->determineRootline($contentElement); - $this->finalSizes = $this->contentElement->getFinalSize([]); - } - - public function getFinalSizes(): array - { - $sizes = $this->finalSizes; + $sizes = $contentElement->getFinalSize([]); - foreach ($sizes as $sizeName => &$size) { + foreach ($sizes as &$size) { $size = ceil($size); } @@ -71,9 +74,10 @@ private function determineBackendLayout(): void { $typoscriptFrontendController = $GLOBALS['TSFE']; - $this->backendLayoutIdentifier = GeneralUtility::makeInstance(PageLayoutResolver::class) - ->getLayoutForPage($typoscriptFrontendController->page, $typoscriptFrontendController->rootLine) - ; + $this->backendLayoutIdentifier = $this->pageLayoutResolver->getLayoutForPage( + $typoscriptFrontendController->page, + $typoscriptFrontendController->rootLine + ); $this->backendLayout = new BackendLayout($this->backendLayoutIdentifier); } diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index a66d1e9..47946d2 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -28,9 +28,6 @@ services: Codappix\ResponsiveImages\DataProcessing\ResponsiveImagesProcessor: public: true - arguments: - $configurationManager: '@Codappix\ResponsiveImages\Configuration\ConfigurationManager' - $containerRepository: '@Codappix\ResponsiveImages\Domain\Repository\ContainerRepository' Codappix\ResponsiveImages\Configuration\ConfigurationManager: public: true @@ -38,6 +35,5 @@ services: $settings: '@extbaseSettings.ResponsiveImages' Codappix\ResponsiveImages\Domain\Repository\ContainerRepository: - public: true arguments: - '@dbconnection.tt_content'