Skip to content

Instantly share code, notes, and snippets.

@davidtsadler
Last active July 28, 2016 14:50
Show Gist options
  • Save davidtsadler/479786334dbeb3bc8c4d0e80123e4d46 to your computer and use it in GitHub Desktop.
Save davidtsadler/479786334dbeb3bc8c4d0e80123e4d46 to your computer and use it in GitHub Desktop.
<?php
class ArrayLike implements JmesPathableArrayInterface
{
private $data = [];
private $position = 0;
public function __construct(array $data = [])
{
$this->data = $data;
}
public function offsetExists($offset)
{
return array_key_exists($offset, $this->data);
}
public function offsetGet($offset)
{
return $this->offsetExists($offset) ? $this->data[$offset] : null;
}
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->data[] = $value;
} else {
$this->data[$offset] = $value;
}
}
public function offsetUnset($offset)
{
unset($this->data[$offset]);
}
public function count()
{
return count($this->data);
}
public function current()
{
return $this->offsetGet($this->position);
}
public function key()
{
return $this->position;
}
public function next()
{
$this->position++;
}
public function rewind()
{
$this->position = 0;
}
public function valid()
{
return $this->offsetExists($this->position);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment