Skip to content

Commit

Permalink
Merge pull request netgen#82 from netgen/slice_array_access
Browse files Browse the repository at this point in the history
Slice needs to implement ArrayAccess
  • Loading branch information
pspanja committed Aug 3, 2018
2 parents 499be98 + 3f8596e commit 160b64c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/Core/Site/Pagination/Pagerfanta/Slice.php
Expand Up @@ -2,15 +2,17 @@

namespace Netgen\EzPlatformSiteApi\Core\Site\Pagination\Pagerfanta;

use ArrayAccess;
use ArrayIterator;
use eZ\Publish\API\Repository\Values\Content\Search\SearchHit;
use IteratorAggregate;
use RuntimeException;

/**
* Implements IteratorAggregate with access to the array of the SearchHit instances
* and aggregated ArrayIterator over values contained in them.
*/
final class Slice implements IteratorAggregate
final class Slice implements IteratorAggregate, ArrayAccess
{
/**
* @var \eZ\Publish\API\Repository\Values\Content\Search\SearchHit[]
Expand Down Expand Up @@ -38,4 +40,24 @@ function (SearchHit $searchHit) {
)
);
}

public function offsetExists($offset)
{
return \array_key_exists($offset, $this->searchHits);
}

public function offsetGet($offset)
{
return $this->searchHits[$offset]->valueObject;
}

public function offsetSet($offset, $value)
{
throw new RuntimeException('Method ' . __METHOD__ . ' is not supported');
}

public function offsetUnset($offset)
{
throw new RuntimeException('Method ' . __METHOD__ . ' is not supported');
}
}

0 comments on commit 160b64c

Please sign in to comment.