Skip to content

Commit

Permalink
added array access to query result
Browse files Browse the repository at this point in the history
  • Loading branch information
matthi4s committed Jan 24, 2019
1 parent a230f75 commit 7154a88
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions src/Query/QueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author Matthias Neid
* @package Aternos\Model\Query
*/
class QueryResult implements \Iterator, \Countable
class QueryResult implements \Iterator, \Countable, \ArrayAccess
{
/**
* Success state of the query
Expand Down Expand Up @@ -52,7 +52,7 @@ public function __construct(bool $success, $result = [])
*/
public function wasSuccessful(): bool
{
return (bool) $this->success;
return (bool)$this->success;
}

/**
Expand Down Expand Up @@ -124,4 +124,47 @@ public function count()
{
return count($this->result);
}

/**
* Whether a offset exists
*
* @param mixed $offset
* @return bool
*/
public function offsetExists($offset)
{
return isset($this->result[$offset]);
}

/**
* Offset to retrieve
*
* @param mixed $offset
* @return mixed
*/
public function offsetGet($offset)
{
return $this->result[$offset];
}

/**
* Offset to set
*
* @param $offset
* @param $value
*/
public function offsetSet($offset, $value)
{
$this->result[$offset] = $value;
}

/**
* Offset to unset
*
* @param $offset
*/
public function offsetUnset($offset)
{
unset($this->result[$offset]);
}
}

0 comments on commit 7154a88

Please sign in to comment.