Skip to content

Commit

Permalink
fixup! IBX-6827: Ranges generators
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Dec 8, 2023
1 parent ca2d9b6 commit 92f2d75
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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');

0 comments on commit 92f2d75

Please sign in to comment.