Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Update Highlight.php #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions src/Highlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ScoutElastic;

class Highlight
class Highlight implements \ArrayAccess, \Iterator
{
/**
* @var array
Expand All @@ -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;
}
}
}

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);
}


}