Skip to content

Commit

Permalink
CLEANUP: Use DI for ContainerRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-codappix committed Apr 9, 2024
1 parent d444a04 commit d4414a5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
12 changes: 6 additions & 6 deletions Classes/DataProcessing/ResponsiveImagesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

use Codappix\ResponsiveImages\Configuration\ConfigurationManager;
use Codappix\ResponsiveImages\Domain\Repository\ContainerRepository;
use Codappix\ResponsiveImages\Sizes\Breakpoint;
use Codappix\ResponsiveImages\Sizes\Rootline;
use TYPO3\CMS\Core\Resource\FileInterface;
Expand All @@ -33,8 +34,6 @@

final class ResponsiveImagesProcessor implements DataProcessorInterface
{
private readonly ConfigurationManager $configurationManager;

/**
* @var FileInterface[]
*/
Expand All @@ -44,9 +43,10 @@ final class ResponsiveImagesProcessor implements DataProcessorInterface

private array $contentElementSizes = [];

public function __construct()
{
$this->configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
public function __construct(
private ConfigurationManager $configurationManager,
private ContainerRepository $containerRepository
) {
}

public function process(
Expand Down Expand Up @@ -76,7 +76,7 @@ public function process(
return $processedData;
}

$this->contentElementSizes = (new Rootline($processedData['data'], $fieldName))->getFinalSizes();
$this->contentElementSizes = (new Rootline($this->containerRepository, $processedData['data'], $fieldName))->getFinalSizes();
$this->calculateFileDimensions();

$targetFieldName = (string) $cObj->stdWrapValue(
Expand Down
11 changes: 6 additions & 5 deletions Classes/Domain/Repository/ContainerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
namespace Codappix\ResponsiveImages\Domain\Repository;

use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Error\Exception;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ContainerRepository
{
public function __construct(
private Connection $connection
) {
}

/**
* @throws \Doctrine\DBAL\Exception
* @throws Exception
*/
public function findByIdentifier(int $identifier): array
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$queryBuilder = $this->connection->createQueryBuilder();
$rawData = $queryBuilder
->select('*')
->from('tt_content')
Expand Down
5 changes: 1 addition & 4 deletions Classes/Sizes/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,17 @@ final class Rootline

private BackendLayout $backendLayout;

private ContainerRepository $containerRepository;

private array $finalSizes = [];

private string $fieldName;

private string $backendLayoutIdentifier;

public function __construct(
private ContainerRepository $containerRepository,
array $data,
string $fieldName
) {
$this->containerRepository = new ContainerRepository();

$this->determineBackendLayout();
$this->fieldName = $fieldName;
$this->contentElement = $this->determineContentElement(null, $data);
Expand Down
19 changes: 19 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ services:
Codappix\ResponsiveImages\:
resource: '../Classes/*'

dbconnection.tt_content:
class: 'TYPO3\CMS\Core\Database\Connection'
factory:
- '@TYPO3\CMS\Core\Database\ConnectionPool'
- 'getConnectionForTable'
arguments:
- 'tt_content'

extbaseSettings.ResponsiveImages:
class: 'array'
factory:
Expand All @@ -18,7 +26,18 @@ services:
$extensionName: 'ResponsiveImages'
$pluginName: ''

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 d4414a5

Please sign in to comment.