diff --git a/Classes/Sizes/AbstractContentElement.php b/Classes/Sizes/AbstractContentElement.php index 153b630..a3e828b 100644 --- a/Classes/Sizes/AbstractContentElement.php +++ b/Classes/Sizes/AbstractContentElement.php @@ -31,6 +31,8 @@ abstract class AbstractContentElement implements ContentElementInterface { protected ConfigurationManager $configurationManager; + protected ScalingConfiguration $scalingConfiguration; + protected int $colPos; protected string $contentType; @@ -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); } } diff --git a/Classes/Sizes/BackendLayout/Column.php b/Classes/Sizes/BackendLayout/Column.php index 5fdccce..a6093da 100644 --- a/Classes/Sizes/BackendLayout/Column.php +++ b/Classes/Sizes/BackendLayout/Column.php @@ -23,31 +23,17 @@ * 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 @@ -55,19 +41,8 @@ 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; } } diff --git a/Classes/Sizes/Container.php b/Classes/Sizes/Container.php index cb6f890..ede0777 100644 --- a/Classes/Sizes/Container.php +++ b/Classes/Sizes/Container.php @@ -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; @@ -69,22 +59,6 @@ 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('.', [ @@ -92,10 +66,7 @@ public function readConfiguration(): void $this->contentType, ]); - [$multiplier, $sizes] = $this->readConfigurationByPath($configurationPath); - - $this->multiplier = $multiplier; - $this->sizes = $sizes; + $this->scalingConfiguration = $this->readConfigurationByPath($configurationPath); } private function determineColumns(): void diff --git a/Classes/Sizes/ContentElement.php b/Classes/Sizes/ContentElement.php index b85e3f1..9176600 100644 --- a/Classes/Sizes/ContentElement.php +++ b/Classes/Sizes/ContentElement.php @@ -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); } } diff --git a/Classes/Sizes/ContentElementInterface.php b/Classes/Sizes/ContentElementInterface.php index 12842bb..93eacd0 100644 --- a/Classes/Sizes/ContentElementInterface.php +++ b/Classes/Sizes/ContentElementInterface.php @@ -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; } diff --git a/Classes/Sizes/Multiplier.php b/Classes/Sizes/Multiplier.php deleted file mode 100644 index 79f0806..0000000 --- a/Classes/Sizes/Multiplier.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -/** - * This class only provides the functionality to parse a string to a correct - * float value. - */ -final class Multiplier -{ - public static function parse(string $value): float - { - $value = str_replace(',', '.', $value); - - return (float) $value; - } -} diff --git a/Classes/Sizes/Rootline.php b/Classes/Sizes/Rootline.php index a84ac3b..ea8754c 100644 --- a/Classes/Sizes/Rootline.php +++ b/Classes/Sizes/Rootline.php @@ -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]; diff --git a/Classes/Sizes/ScalingConfiguration.php b/Classes/Sizes/ScalingConfiguration.php new file mode 100644 index 0000000..6a2fdd7 --- /dev/null +++ b/Classes/Sizes/ScalingConfiguration.php @@ -0,0 +1,45 @@ +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; + } +} diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript index 789c1d7..df04d23 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-33-66.typoscript @@ -7,9 +7,9 @@ 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 } } @@ -17,9 +17,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,666 - lg = 0,666 - xl = 0,666 + md = 0.666 + lg = 0.666 + xl = 0.666 } } } diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-multiplier.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-multiplier.typoscript index 0777761..5b5673d 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-multiplier.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-multiplier.typoscript @@ -7,9 +7,9 @@ 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 } } @@ -17,9 +17,9 @@ 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 } } } diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-size.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-size.typoscript index 597946e..1026963 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-size.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50-with-container-size.typoscript @@ -7,9 +7,9 @@ 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 } } @@ -17,9 +17,9 @@ 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 } } } diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript index 33a760c..bc7746f 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-50-50.typoscript @@ -7,9 +7,9 @@ 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 } } @@ -17,9 +17,9 @@ 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 } } } diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript index 4266f20..257c424 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/2col-66-33.typoscript @@ -7,9 +7,9 @@ plugin.tx_responsiveimages { multiplier { xs = 1 sm = 1 - md = 0,666 - lg = 0,666 - xl = 0,666 + md = 0.666 + lg = 0.666 + xl = 0.666 } } @@ -17,9 +17,9 @@ 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 } } } diff --git a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript index 2a283ea..64d5b27 100644 --- a/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript +++ b/Tests/Fixtures/container_example/Configuration/TypoScript/Container/3col.typoscript @@ -7,9 +7,9 @@ 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 } } @@ -17,9 +17,9 @@ 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 } } @@ -27,9 +27,9 @@ 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 } } }