-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/contracts/Repository/Iterator/BatchIteratorAdapter/RelationListIteratorAdapter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter; | ||
|
||
use Ibexa\Contracts\Core\Repository\ContentService; | ||
use Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\RelationType; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; | ||
use Iterator; | ||
use IteratorIterator; | ||
|
||
final class RelationListIteratorAdapter implements BatchIteratorAdapter | ||
{ | ||
public function __construct( | ||
readonly private ContentService $contentService, | ||
readonly private VersionInfo $versionInfo, | ||
readonly private ?RelationType $relationType = null, | ||
) { | ||
} | ||
|
||
public function fetch(int $offset, int $limit): Iterator | ||
{ | ||
$iterator = $this->contentService->loadRelationList( | ||
$this->versionInfo, | ||
$offset, | ||
$limit, | ||
$this->relationType | ||
)->getIterator(); | ||
|
||
if ($iterator instanceof Iterator) { | ||
return $iterator; | ||
} | ||
|
||
return new IteratorIterator($iterator); | ||
} | ||
} |