Skip to content

Commit

Permalink
CLEANUP: Use arrays for retrieving information from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-codappix committed Apr 10, 2024
1 parent 92182ff commit da627d6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 63 deletions.
8 changes: 4 additions & 4 deletions Classes/Configuration/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public function get(): array
return $this->settings;
}

public function isValidPath(string $path): bool
public function isValidPath(array|string $path): bool
{
return ArrayUtility::isValidPath($this->settings, $path, '.');
return ArrayUtility::isValidPath($this->settings, $path);
}

public function getByPath(string $path): mixed
public function getByPath(array|string $path): mixed
{
return ArrayUtility::getValueByPath($this->settings, $path, '.');
return ArrayUtility::getValueByPath($this->settings, $path);
}
}
2 changes: 1 addition & 1 deletion Classes/DataProcessing/ResponsiveImagesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private function getBreakpoints(): array
{
$breakpoints = [];

$breakpointsByPath = $this->configurationManager->getByPath('breakpoints');
$breakpointsByPath = $this->configurationManager->getByPath(['breakpoints']);

if (is_iterable($breakpointsByPath)) {
foreach ($breakpointsByPath as $breakpointIdentifier => $breakpointData) {
Expand Down
10 changes: 6 additions & 4 deletions Classes/Domain/Factory/BackendLayoutFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@
class BackendLayoutFactory
{
public function __construct(
private ConfigurationManager $configurationManager,
private readonly ConfigurationManager $configurationManager,
private readonly ScalingFactory $scalingFactory
) {
}

public function create(string $configurationPath): BackendLayoutInterface
public function create(array $configurationPath): BackendLayoutInterface
{
$scaling = $this->scalingFactory->getByConfigurationPath($configurationPath);

$columns = $this->determineColumns($configurationPath . '.columns');
$configurationPath[] = 'columns';

$columns = $this->determineColumns($configurationPath);

return new BackendLayout($scaling, $columns);
}

private function determineColumns(string $configurationPath): array
private function determineColumns(array $configurationPath): array
{
$columns = $this->configurationManager->getByPath($configurationPath);
assert(is_array($columns));
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Factory/RootlineElementFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
) {
}

public function create(array $data, string $configurationPath): RootlineElementInterface
public function create(array $data, array|string $configurationPath): RootlineElementInterface
{
$scaling = $this->scalingFactory->getByConfigurationPath($configurationPath);

Expand Down
86 changes: 34 additions & 52 deletions Classes/Domain/Factory/RootlineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public function determineContainerColumn(
): RootlineElementInterface {
$newContainerColumn = $this->rootlineElementFactory->create(
$data,
$this->getConfigPathForContainerColumn($data['CType'], $contentElement)
[
'container',
$data['CType'],
'columns',
(string) $contentElement->getColPos(),
]
);
$contentElement->setParent($newContainerColumn);

Expand All @@ -86,48 +91,59 @@ private function determineBackendLayout(): void
);

$this->backendLayout = $this->backendLayoutFactory->create(
$this->getConfigPathForBackendLayout()
[
'backendlayouts',
$this->backendLayoutIdentifier,
]
);
}

private function determineBackendLayoutColumn(RootlineElementInterface $contentElement): void
{
$newBackendLayoutColumn = $this->rootlineElementFactory->create(
[],
$this->getConfigPathForBackendLayoutColumn($contentElement)
[
'backendlayouts',
$this->backendLayoutIdentifier,
'columns',
(string) $contentElement->getColPos(),
]
);

$newBackendLayoutColumn->setParent($this->backendLayout);
$contentElement->setParent($newBackendLayoutColumn);
}

private function determineContentElement(
array $data,
string $fieldName
): RootlineElementInterface {
return $this->rootlineElementFactory->create(
$data,
implode('.', [
'contentelements',
$data['CType'],
$fieldName,
])
);
}

private function determineContainer(array $data, RootlineElementInterface $contentElement): RootlineElementInterface
{
$newContainerColumn = $this->determineContainerColumn($data, $contentElement);

$newContainer = $this->rootlineElementFactory->create(
$data,
$this->getConfigPathForContainer($data['CType'])
[
'container',
$data['CType'],
]
);
$newContainerColumn->setParent($newContainer);

return $newContainer;
}

private function determineContentElement(
array $data,
string $fieldName
): RootlineElementInterface {
return $this->rootlineElementFactory->create(
$data,
[
'contentelements',
$data['CType'],
$fieldName,
]
);
}

private function determineRootline(RootlineElementInterface $contentElement): void
{
if (in_array($contentElement->getColPos(), $this->backendLayout->getColumns(), true)) {
Expand All @@ -148,38 +164,4 @@ private function determineRootline(RootlineElementInterface $contentElement): vo
$this->determineRootline($parent);
}
}

private function getConfigPathForContainer(string $CType): string
{
return implode('.', [
'container',
$CType,
]);
}

private function getConfigPathForContainerColumn(string $CType, RootlineElementInterface $contentElement): string
{
return implode('.', [
$this->getConfigPathForContainer($CType),
'columns',
(string) $contentElement->getColPos(),
]);
}

private function getConfigPathForBackendLayout(): string
{
return implode('.', [
'backendlayouts',
$this->backendLayoutIdentifier,
]);
}

private function getConfigPathForBackendLayoutColumn(RootlineElementInterface $contentElement): string
{
return implode('.', [
$this->getConfigPathForBackendLayout(),
'columns',
(string) $contentElement->getColPos(),
]);
}
}
2 changes: 1 addition & 1 deletion Classes/Domain/Factory/ScalingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
) {
}

public function getByConfigurationPath(string $configurationPath): Scaling
public function getByConfigurationPath(array|string $configurationPath): Scaling
{
$configuration = $this->configurationManager->getByPath($configurationPath);
$multiplier = [];
Expand Down

0 comments on commit da627d6

Please sign in to comment.