diff --git a/src/Highlight.php b/src/Highlight.php index ab34fd2..fb23b11 100644 --- a/src/Highlight.php +++ b/src/Highlight.php @@ -2,7 +2,7 @@ namespace ScoutElastic; -class Highlight +class Highlight implements \ArrayAccess, \Iterator { /** * @var array @@ -27,9 +27,63 @@ public function __get($key) if (isset($this->highlight[$field])) { $value = $this->highlight[$field]; + return $field == $key ? $value : implode(' ', $value); } else { return null; } } -} \ No newline at end of file + + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->highlight[] = $value; + } else { + $this->highlight[$offset] = $value; + } + } + + public function offsetExists($offset) + { + return isset($this->highlight[$offset]); + } + + public function offsetUnset($offset) + { + unset($this->highlight[$offset]); + } + + public function offsetGet($offset) + { + return isset($this->highlight[$offset]) ? $this->highlight[$offset] : null; + } + + public function current() + { + return current($this->highlight); + } + + public function next() + { + return next($this->highlight); + } + + public function key() + { + return key($this->highlight); + } + + public function valid() + { + $key = key($this->highlight); + + return ($key !== null && $key !== false); + } + + public function rewind() + { + reset($this->highlight); + } + + +}