Skip to content
Snippets Groups Projects
Commit c1c3bd9d authored by Alan Sherry's avatar Alan Sherry
Browse files

Issue #3407114: Fixes getData function to return iterable data that can be overridden

parent a242b736
No related branches found
No related tags found
1 merge request!8Removes deprecated model naming scheme and moves client object naming over to...
......@@ -10,52 +10,64 @@ use Traversable;
/**
* A hybrid class to allow array iterating and ResponseInterface functionality.
*/
class IterableResponse extends Response implements \IteratorAggregate, \Countable, \ArrayAccess
{
class IterableResponse extends Response implements \IteratorAggregate, \Countable, \ArrayAccess {
protected $responseData;
protected $iterableData;
public function getIterator(): Traversable
{
/**
* {@inheritdoc}
*/
public function getIterator(): Traversable {
return new \ArrayIterator($this->iterableData);
}
public function count(): int
{
/**
* {@inheritdoc}
*/
public function count(): int {
return count($this->iterableData);
}
public function offsetExists(mixed $offset): bool
{
/**
* {@inheritdoc}
*/
public function offsetExists(mixed $offset): bool {
return isset($this->iterableData[$offset]);
}
public function offsetGet(mixed $offset): mixed
{
/**
* {@inheritdoc}
*/
public function offsetGet(mixed $offset): mixed {
return $this->offsetExists($offset) ? $this->iterableData[$offset] : NULL;
}
public function offsetSet(mixed $offset, mixed $value): void
{
/**
* {@inheritdoc}
*/
public function offsetSet(mixed $offset, mixed $value): void {
$this->iterableData[$offset] = $value;
}
public function offsetUnset(mixed $offset): void
{
/**
* {@inheritdoc}
*/
public function offsetUnset(mixed $offset): void {
unset($this->iterableData[$offset]);
}
public function __construct(array $parents, $data, $status = 200, array $headers = [], $body = null, $version = '1.1', $reason = null)
{
/**
* {@inheritdoc}
*/
public function __construct(array $parents, $data, $status = 200, array $headers = [], $body = null, $version = '1.1', $reason = null) {
parent::__construct($status, $headers, $body, $version, $reason);
$this->responseData = $data;
$this->iterableData = &NestedArray::getValue($data, $parents);
}
public static function create(array $parents, array $data, ResponseInterface $response)
{
public static function create(array $parents, array $data, ResponseInterface $response) {
return new static(
$parents,
$data,
......@@ -67,8 +79,11 @@ class IterableResponse extends Response implements \IteratorAggregate, \Countabl
);
}
public function getData()
{
public function getData() {
return $this->iterableData;
}
public function getResponseData() {
return $this->responseData;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment