Skip to content

Commit 90dc25a

Browse files
committed
Implement ArrayAccess
1 parent 719982b commit 90dc25a

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

src/Responses/ResponseObject.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace GetCandy\Client\Responses;
44

5+
use ArrayAccess;
56
use Illuminate\Support\Collection;
67
use Illuminate\Contracts\Support\Arrayable;
78

8-
class ResponseObject implements Arrayable
9+
class ResponseObject implements Arrayable, ArrayAccess
910
{
1011
protected $attributes = [];
1112

@@ -55,4 +56,49 @@ public function toArray()
5556

5657
return $data;
5758
}
59+
60+
/**
61+
* Determine if the given attribute exists.
62+
*
63+
* @param mixed $offset
64+
* @return bool
65+
*/
66+
public function offsetExists($offset)
67+
{
68+
return ! is_null($this->getAttribute($offset));
69+
}
70+
71+
/**
72+
* Get the value for a given offset.
73+
*
74+
* @param mixed $offset
75+
* @return mixed
76+
*/
77+
public function offsetGet($offset)
78+
{
79+
return $this->getAttribute($offset);
80+
}
81+
82+
/**
83+
* Set the value for a given offset.
84+
*
85+
* @param mixed $offset
86+
* @param mixed $value
87+
* @return void
88+
*/
89+
public function offsetSet($offset, $value)
90+
{
91+
$this->setAttribute($offset, $value);
92+
}
93+
94+
/**
95+
* Unset the value for a given offset.
96+
*
97+
* @param mixed $offset
98+
* @return void
99+
*/
100+
public function offsetUnset($offset)
101+
{
102+
unset($this->attributes[$offset], $this->relations[$offset]);
103+
}
58104
}

0 commit comments

Comments
 (0)