Skip to content

Commit e525968

Browse files
committed
TASK: improve LimitEnumerator for debugging
1 parent 65ef99c commit e525968

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

Classes/NodeRendering/Extensibility/DocumentEnumerators/LimitEnumerator.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,29 @@
1313
class LimitEnumerator implements DocumentEnumeratorInterface
1414
{
1515
protected int $i = 0;
16-
private int $limit;
16+
private ?int $limit = null;
17+
private ?string $uriPathSegmentFilter = null;
1718

1819
public function __construct(
1920
array $options = []
2021
) {
21-
$this->limit = $options['limit'] ?? throw new \InvalidArgumentException('Missing limit option');
22+
$this->limit = $options['limit'] ?? null;
23+
$this->uriPathSegmentFilter = $options['uriPathSegmentFilter'] ?? null;
2224
}
2325
public function enumerateDocumentNode(NodeInterface $documentNode): iterable
2426
{
25-
if ($this->i++ >= $this->limit) {
26-
return [];
27+
if ($this->uriPathSegmentFilter !== null) {
28+
if (str_contains($documentNode->getProperty('uriPathSegment'), $this->uriPathSegmentFilter) === false) {
29+
return [];
30+
}
31+
}
32+
33+
// NOTE: Limiting must come LAST, after all other constraints have been evaluated (because we want
34+
// only filtered nodes from the other conditions to be counted against the limit)
35+
if ($this->limit !== null) {
36+
if ($this->i++ >= $this->limit) {
37+
return [];
38+
}
2739
}
2840

2941
return [

Configuration/Settings.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Flowpack:
5757
enumeratorClassName: Flowpack\DecoupledContentStore\NodeRendering\Extensibility\DocumentEnumerators\DefaultEnumerator
5858
#enumeratorClassName: Flowpack\DecoupledContentStore\NodeRendering\Extensibility\DocumentEnumerators\LimitEnumerator
5959
#enumeratorOptions:
60+
# uriPathSegmentFilter: vanucci-collection
6061
# limit: 20
6162
rendererClassName: Flowpack\DecoupledContentStore\NodeRendering\Extensibility\DocumentRenderers\FusionHtmlRenderer
6263

0 commit comments

Comments
 (0)