Skip to content

Commit

Permalink
CLEANUP: Move $multiplier and $sizes to ScalungConfiguration Object
Browse files Browse the repository at this point in the history
Relates: #22, relates: #24
  • Loading branch information
d-g-codappix committed Apr 5, 2024
1 parent 3e4c5fa commit 491c101
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 193 deletions.
25 changes: 11 additions & 14 deletions Classes/Sizes/AbstractContentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ abstract class AbstractContentElement implements ContentElementInterface
{
protected ConfigurationManager $configurationManager;

protected ScalingConfiguration $scalingConfiguration;

protected int $colPos;

protected string $contentType;
Expand Down Expand Up @@ -85,23 +87,18 @@ public function setParent(ContentElementInterface $contentElement): void
$this->parent = $contentElement;
}

protected function readConfigurationByPath(string $configurationPath): array
public function getScalingConfiguration(): ScalingConfiguration
{
$configuration = $this->configurationManager->getByPath($configurationPath);

$multiplier = [];
$sizes = [];

if (is_array($configuration)) {
if (isset($configuration['multiplier'])) {
$multiplier = array_map(static fn ($multiplier): float => Multiplier::parse($multiplier), $configuration['multiplier']);
}
return $this->scalingConfiguration;
}

if (isset($configuration['sizes'])) {
$sizes = array_map(static fn ($size): int => (int) $size, $configuration['sizes']);
}
protected function readConfigurationByPath(string $configurationPath): ScalingConfiguration
{
$configuration = $this->configurationManager->getByPath($configurationPath);
if (!is_array($configuration)) {
$configuration = [];
}

return [$multiplier, $sizes];
return new ScalingConfiguration($configuration);
}
}
35 changes: 5 additions & 30 deletions Classes/Sizes/BackendLayout/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,26 @@
* 02110-1301, USA.
*/

use Codappix\ResponsiveImages\Sizes\Multiplier;
use Codappix\ResponsiveImages\Sizes\ScalingConfiguration;

class Column
{
/**
* @var float[]
*/
private array $multiplier = [];

/**
* @var int[]
*/
private array $sizes = [];
protected ScalingConfiguration $scalingConfiguration;

public function __construct(
private readonly int $identifier,
array $data
) {
if (isset($data['multiplier'])) {
$this->multiplier = array_map(static fn ($multiplier): float => Multiplier::parse($multiplier), $data['multiplier']);
}

if (isset($data['sizes'])) {
$this->sizes = array_map(static fn ($size): int => (int) $size, $data['sizes']);
}
$this->scalingConfiguration = new ScalingConfiguration($data);
}

public function getIdentifier(): int
{
return $this->identifier;
}

/**
* @return float[]
*/
public function getMultiplier(): array
{
return $this->multiplier;
}

/**
* @return int[]
*/
public function getSizes(): array
public function getScalingConfiguration(): ScalingConfiguration
{
return $this->sizes;
return $this->scalingConfiguration;
}
}
31 changes: 1 addition & 30 deletions Classes/Sizes/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@

final class Container extends AbstractContentElement
{
/**
* @var float[]
*/
private array $multiplier = [];

/**
* @var int[]
*/
private array $sizes = [];

private array $columns = [];

private Column $activeColumn;
Expand Down Expand Up @@ -69,33 +59,14 @@ public function getActiveColumn(): Column
return $this->activeColumn;
}

/**
* @return float[]
*/
public function getMultiplier(): array
{
return $this->multiplier;
}

/**
* @return int[]
*/
public function getSizes(): array
{
return $this->sizes;
}

public function readConfiguration(): void
{
$configurationPath = implode('.', [
'container',
$this->contentType,
]);

[$multiplier, $sizes] = $this->readConfigurationByPath($configurationPath);

$this->multiplier = $multiplier;
$this->sizes = $sizes;
$this->scalingConfiguration = $this->readConfigurationByPath($configurationPath);
}

private function determineColumns(): void
Expand Down
36 changes: 1 addition & 35 deletions Classes/Sizes/ContentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,18 @@

class ContentElement extends AbstractContentElement
{
/**
* @var float[]
*/
private array $multiplier = [];

/**
* @var int[]
*/
private array $sizes = [];

public function __construct(
array $data,
private readonly string $fieldName
) {
parent::__construct($data);

$this->readConfiguration();
}

/**
* @return float[]
*/
public function getMultiplier(): array
{
return $this->multiplier;
}

/**
* @return int[]
*/
public function getSizes(): array
{
return $this->sizes;
}

public function readConfiguration(): void
{
$configurationPath = implode('.', [
'contentelements',
$this->contentType,
$this->fieldName,
]);

[$multiplier, $sizes] = $this->readConfigurationByPath($configurationPath);

$this->multiplier = $multiplier;
$this->sizes = $sizes;
$this->scalingConfiguration = $this->readConfigurationByPath($configurationPath);
}
}
4 changes: 1 addition & 3 deletions Classes/Sizes/ContentElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ public function setParent(self $contentElement): void;

public function getParent(): ?self;

public function getSizes(): array;

public function getMultiplier(): array;
public function getScalingConfiguration(): ScalingConfiguration;
}
38 changes: 0 additions & 38 deletions Classes/Sizes/Multiplier.php

This file was deleted.

8 changes: 4 additions & 4 deletions Classes/Sizes/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ public function getSizesAndMultiplierFromContentElement(
): array {
if ($contentElement instanceof ContentElementInterface) {
if ($contentElement instanceof Container) {
$sizes = $contentElement->getActiveColumn()->getSizes();
$sizes = $contentElement->getActiveColumn()->getScalingConfiguration()->getSizes();
if (!empty($sizes)) {
return [$sizes, $multiplier];
}

$multiplier[] = $contentElement->getActiveColumn()->getMultiplier();
$multiplier[] = $contentElement->getActiveColumn()->getScalingConfiguration()->getMultiplier();
}

$sizes = $contentElement->getSizes();
$sizes = $contentElement->getScalingConfiguration()->getSizes();
if (!empty($sizes)) {
return [$sizes, $multiplier];
}

$multiplier[] = $contentElement->getMultiplier();
$multiplier[] = $contentElement->getScalingConfiguration()->getMultiplier();
}

return [$sizes, $multiplier];
Expand Down
45 changes: 45 additions & 0 deletions Classes/Sizes/ScalingConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Codappix\ResponsiveImages\Sizes;

class ScalingConfiguration
{
/**
* @var float[]
*/
private array $multiplier = [];

/**
* @var int[]
*/
private array $sizes = [];

public function __construct(array $configuration)
{
if (isset($configuration['multiplier'])) {
$this->multiplier = array_map(static fn ($multiplier): float => (float) $multiplier, $configuration['multiplier']);
}

if (isset($configuration['sizes'])) {
$this->sizes = array_map(static fn ($size): int => (int) $size, $configuration['sizes']);
}
}

/**
* @return float[]
*/
public function getMultiplier(): array
{
return $this->multiplier;
}

/**
* @return int[]
*/
public function getSizes(): array
{
return $this->sizes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ plugin.tx_responsiveimages {
multiplier {
xs = 1
sm = 1
md = 0,333
lg = 0,333
xl = 0,333
md = 0.333
lg = 0.333
xl = 0.333
}
}

102 {
multiplier {
xs = 1
sm = 1
md = 0,666
lg = 0,666
xl = 0,666
md = 0.666
lg = 0.666
xl = 0.666
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ plugin.tx_responsiveimages {
multiplier {
xs = 1
sm = 1
md = 0,5
lg = 0,5
xl = 0,5
md = 0.5
lg = 0.5
xl = 0.5
}
}

102 {
multiplier {
xs = 1
sm = 1
md = 0,5
lg = 0,5
xl = 0,5
md = 0.5
lg = 0.5
xl = 0.5
}
}
}
Expand Down
Loading

0 comments on commit 491c101

Please sign in to comment.