From 92f2d7530e5ed9d24041a228b3274a710c7f7b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Wed, 6 Dec 2023 23:59:41 +0100 Subject: [PATCH] fixup! IBX-6827: Ranges generators --- .../Aggregation/DateMetadataRangeAggregation.php | 16 ++++++++++++++++ .../Field/AbstractFieldRangeAggregation.php | 16 ---------------- .../Aggregation/Field/DateRangeAggregation.php | 16 ++++++++++++++++ .../Field/DateTimeRangeAggregation.php | 16 ++++++++++++++++ .../Aggregation/Field/FloatRangeAggregation.php | 16 ++++++++++++++++ .../Field/IntegerRangeAggregation.php | 16 ++++++++++++++++ .../Aggregation/Field/TimeRangeAggregation.php | 16 ++++++++++++++++ .../Ranges/IntegerStepRangesGenerator.php | 2 +- .../Query/Aggregation/RawRangeAggregation.php | 16 ++++++++++++++++ 9 files changed, 113 insertions(+), 17 deletions(-) diff --git a/src/contracts/Repository/Values/Content/Query/Aggregation/DateMetadataRangeAggregation.php b/src/contracts/Repository/Values/Content/Query/Aggregation/DateMetadataRangeAggregation.php index 33d54bf039..2dfa08ad53 100644 --- a/src/contracts/Repository/Values/Content/Query/Aggregation/DateMetadataRangeAggregation.php +++ b/src/contracts/Repository/Values/Content/Query/Aggregation/DateMetadataRangeAggregation.php @@ -8,6 +8,9 @@ namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\RangesGeneratorInterface; +use Traversable; + final class DateMetadataRangeAggregation extends AbstractRangeAggregation { public const MODIFIED = 'modified'; @@ -27,6 +30,19 @@ public function getType(): string { return $this->type; } + + public static function fromGenerator( + string $name, + string $type, + RangesGeneratorInterface $generator + ): self { + $ranges = $generator->generate(); + if ($ranges instanceof Traversable) { + $ranges = iterator_to_array($ranges); + } + + return new self($name, $type, $ranges); + } } class_alias(DateMetadataRangeAggregation::class, 'eZ\Publish\API\Repository\Values\Content\Query\Aggregation\DateMetadataRangeAggregation'); diff --git a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/AbstractFieldRangeAggregation.php b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/AbstractFieldRangeAggregation.php index 41ce7ece7e..e63e888c96 100644 --- a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/AbstractFieldRangeAggregation.php +++ b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/AbstractFieldRangeAggregation.php @@ -10,8 +10,6 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\AbstractRangeAggregation; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\FieldAggregation; -use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\RangesGeneratorInterface; -use Traversable; abstract class AbstractFieldRangeAggregation extends AbstractRangeAggregation implements FieldAggregation { @@ -28,20 +26,6 @@ public function __construct( $this->contentTypeIdentifier = $contentTypeIdentifier; $this->fieldDefinitionIdentifier = $fieldDefinitionIdentifier; } - - public static function fromGenerator( - string $name, - string $contentTypeIdentifier, - string $fieldDefinitionIdentifier, - RangesGeneratorInterface $generator - ): self { - $ranges = $generator->generate(); - if ($ranges instanceof Traversable) { - $ranges = iterator_to_array($ranges); - } - - return new static($name, $contentTypeIdentifier, $fieldDefinitionIdentifier, $ranges); - } } class_alias(AbstractFieldRangeAggregation::class, 'eZ\Publish\API\Repository\Values\Content\Query\Aggregation\Field\AbstractFieldRangeAggregation'); diff --git a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/DateRangeAggregation.php b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/DateRangeAggregation.php index 0be15c9413..8b225caf25 100644 --- a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/DateRangeAggregation.php +++ b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/DateRangeAggregation.php @@ -8,8 +8,24 @@ namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Field; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\RangesGeneratorInterface; +use Traversable; + final class DateRangeAggregation extends AbstractFieldRangeAggregation { + public static function fromGenerator( + string $name, + string $contentTypeIdentifier, + string $fieldDefinitionIdentifier, + RangesGeneratorInterface $generator + ): self { + $ranges = $generator->generate(); + if ($ranges instanceof Traversable) { + $ranges = iterator_to_array($ranges); + } + + return new self($name, $contentTypeIdentifier, $fieldDefinitionIdentifier, $ranges); + } } class_alias(DateRangeAggregation::class, 'eZ\Publish\API\Repository\Values\Content\Query\Aggregation\Field\DateRangeAggregation'); diff --git a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/DateTimeRangeAggregation.php b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/DateTimeRangeAggregation.php index a6a155b62b..3963444ecc 100644 --- a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/DateTimeRangeAggregation.php +++ b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/DateTimeRangeAggregation.php @@ -8,8 +8,24 @@ namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Field; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\RangesGeneratorInterface; +use Traversable; + final class DateTimeRangeAggregation extends AbstractFieldRangeAggregation { + public static function fromGenerator( + string $name, + string $contentTypeIdentifier, + string $fieldDefinitionIdentifier, + RangesGeneratorInterface $generator + ): self { + $ranges = $generator->generate(); + if ($ranges instanceof Traversable) { + $ranges = iterator_to_array($ranges); + } + + return new self($name, $contentTypeIdentifier, $fieldDefinitionIdentifier, $ranges); + } } class_alias(DateTimeRangeAggregation::class, 'eZ\Publish\API\Repository\Values\Content\Query\Aggregation\Field\DateTimeRangeAggregation'); diff --git a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/FloatRangeAggregation.php b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/FloatRangeAggregation.php index 9c2ad230c2..188a15396f 100644 --- a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/FloatRangeAggregation.php +++ b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/FloatRangeAggregation.php @@ -8,8 +8,24 @@ namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Field; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\RangesGeneratorInterface; +use Traversable; + final class FloatRangeAggregation extends AbstractFieldRangeAggregation { + public static function fromGenerator( + string $name, + string $contentTypeIdentifier, + string $fieldDefinitionIdentifier, + RangesGeneratorInterface $generator + ): self { + $ranges = $generator->generate(); + if ($ranges instanceof Traversable) { + $ranges = iterator_to_array($ranges); + } + + return new self($name, $contentTypeIdentifier, $fieldDefinitionIdentifier, $ranges); + } } class_alias(FloatRangeAggregation::class, 'eZ\Publish\API\Repository\Values\Content\Query\Aggregation\Field\FloatRangeAggregation'); diff --git a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/IntegerRangeAggregation.php b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/IntegerRangeAggregation.php index 3fdde15481..e79fe6dd28 100644 --- a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/IntegerRangeAggregation.php +++ b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/IntegerRangeAggregation.php @@ -8,8 +8,24 @@ namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Field; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\RangesGeneratorInterface; +use Traversable; + final class IntegerRangeAggregation extends AbstractFieldRangeAggregation { + public static function fromGenerator( + string $name, + string $contentTypeIdentifier, + string $fieldDefinitionIdentifier, + RangesGeneratorInterface $generator + ): self { + $ranges = $generator->generate(); + if ($ranges instanceof Traversable) { + $ranges = iterator_to_array($ranges); + } + + return new static($name, $contentTypeIdentifier, $fieldDefinitionIdentifier, $ranges); + } } class_alias(IntegerRangeAggregation::class, 'eZ\Publish\API\Repository\Values\Content\Query\Aggregation\Field\IntegerRangeAggregation'); diff --git a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/TimeRangeAggregation.php b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/TimeRangeAggregation.php index 7b2d5c9c7c..30907ec4b1 100644 --- a/src/contracts/Repository/Values/Content/Query/Aggregation/Field/TimeRangeAggregation.php +++ b/src/contracts/Repository/Values/Content/Query/Aggregation/Field/TimeRangeAggregation.php @@ -8,8 +8,24 @@ namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Field; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\RangesGeneratorInterface; +use Traversable; + final class TimeRangeAggregation extends AbstractFieldRangeAggregation { + public static function fromGenerator( + string $name, + string $contentTypeIdentifier, + string $fieldDefinitionIdentifier, + RangesGeneratorInterface $generator + ): self { + $ranges = $generator->generate(); + if ($ranges instanceof Traversable) { + $ranges = iterator_to_array($ranges); + } + + return new self($name, $contentTypeIdentifier, $fieldDefinitionIdentifier, $ranges); + } } class_alias(TimeRangeAggregation::class, 'eZ\Publish\API\Repository\Values\Content\Query\Aggregation\Field\TimeRangeAggregation'); diff --git a/src/contracts/Repository/Values/Content/Query/Aggregation/Ranges/IntegerStepRangesGenerator.php b/src/contracts/Repository/Values/Content/Query/Aggregation/Ranges/IntegerStepRangesGenerator.php index 015ec765df..b728057d90 100644 --- a/src/contracts/Repository/Values/Content/Query/Aggregation/Ranges/IntegerStepRangesGenerator.php +++ b/src/contracts/Repository/Values/Content/Query/Aggregation/Ranges/IntegerStepRangesGenerator.php @@ -90,7 +90,7 @@ public function setRightOpen(bool $isRightOpen): self } /** - * @return \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range[] + * @return \Generator<\Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Range> */ public function generate(): Generator { diff --git a/src/contracts/Repository/Values/Content/Query/Aggregation/RawRangeAggregation.php b/src/contracts/Repository/Values/Content/Query/Aggregation/RawRangeAggregation.php index a5ebeabd43..2aac8a6bb8 100644 --- a/src/contracts/Repository/Values/Content/Query/Aggregation/RawRangeAggregation.php +++ b/src/contracts/Repository/Values/Content/Query/Aggregation/RawRangeAggregation.php @@ -8,6 +8,9 @@ namespace Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation; +use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\Ranges\RangesGeneratorInterface; +use Traversable; + final class RawRangeAggregation extends AbstractRangeAggregation implements RawAggregation { /** @var string */ @@ -24,6 +27,19 @@ public function getFieldName(): string { return $this->fieldName; } + + public static function fromGenerator( + string $name, + string $fieldName, + RangesGeneratorInterface $generator + ): self { + $ranges = $generator->generate(); + if ($ranges instanceof Traversable) { + $ranges = iterator_to_array($ranges); + } + + return new self($name, $fieldName, $ranges); + } } class_alias(RawRangeAggregation::class, 'eZ\Publish\API\Repository\Values\Content\Query\Aggregation\RawRangeAggregation');