Skip to content

Commit

Permalink
CLEANUP: Make Rootline class a factory
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-codappix committed Apr 9, 2024
1 parent 941c219 commit ff1e07c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
7 changes: 3 additions & 4 deletions Classes/DataProcessing/ResponsiveImagesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,7 +43,7 @@ final class ResponsiveImagesProcessor implements DataProcessorInterface

public function __construct(
private ConfigurationManager $configurationManager,
private ContainerRepository $containerRepository
private RootlineFactory $rootlineFactory
) {
}

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Codappix\ResponsiveImages\Sizes;
namespace Codappix\ResponsiveImages\Domain\Factory;

/*
* Copyright (C) 2024 Justus Moroni <[email protected]>
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ 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
arguments:
$settings: '@extbaseSettings.ResponsiveImages'

Codappix\ResponsiveImages\Domain\Repository\ContainerRepository:
public: true
arguments:
- '@dbconnection.tt_content'

0 comments on commit ff1e07c

Please sign in to comment.