47 lines
922 B
PHP
47 lines
922 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace DMS\PHPUnitExtensions\ArraySubset;
|
|
|
|
use ArrayAccess;
|
|
use ArrayIterator;
|
|
use IteratorAggregate;
|
|
|
|
class ArrayAccessible implements ArrayAccess, IteratorAggregate
|
|
{
|
|
private $array;
|
|
|
|
public function __construct(array $array = [])
|
|
{
|
|
$this->array = $array;
|
|
}
|
|
|
|
public function offsetExists($offset)
|
|
{
|
|
return \array_key_exists($offset, $this->array);
|
|
}
|
|
|
|
public function offsetGet($offset)
|
|
{
|
|
return $this->array[$offset];
|
|
}
|
|
|
|
public function offsetSet($offset, $value): void
|
|
{
|
|
if (null === $offset) {
|
|
$this->array[] = $value;
|
|
} else {
|
|
$this->array[$offset] = $value;
|
|
}
|
|
}
|
|
|
|
public function offsetUnset($offset): void
|
|
{
|
|
unset($this->array[$offset]);
|
|
}
|
|
|
|
public function getIterator()
|
|
{
|
|
return new ArrayIterator($this->array);
|
|
}
|
|
}
|