Last active
July 28, 2016 14:50
-
-
Save davidtsadler/479786334dbeb3bc8c4d0e80123e4d46 to your computer and use it in GitHub Desktop.
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
<?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