From e6cd784994da62de0867370e71745a804d17463e Mon Sep 17 00:00:00 2001 From: Erik Wiesenthal Date: Mon, 4 Feb 2019 19:06:58 +0100 Subject: [PATCH] Update Highlight.php https://github.com/babenkoivan/scout-elasticsearch-driver/issues/152 --- src/Highlight.php | 58 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) 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); + } + + +}