scratch – Blame information for rev 87
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
87 | office | 1 | <?php |
2 | |||
3 | namespace GuzzleHttp; |
||
4 | |||
5 | /** |
||
6 | * Trait implementing ToArrayInterface, \ArrayAccess, \Countable, |
||
7 | * \IteratorAggregate, and some path style methods. |
||
8 | */ |
||
9 | trait HasDataTrait |
||
10 | { |
||
11 | /** @var array */ |
||
12 | protected $data = []; |
||
13 | |||
14 | public function getIterator() |
||
15 | { |
||
16 | return new \ArrayIterator($this->data); |
||
17 | } |
||
18 | |||
19 | public function offsetGet($offset) |
||
20 | { |
||
21 | return isset($this->data[$offset]) ? $this->data[$offset] : null; |
||
22 | } |
||
23 | |||
24 | public function offsetSet($offset, $value) |
||
25 | { |
||
26 | $this->data[$offset] = $value; |
||
27 | } |
||
28 | |||
29 | public function offsetExists($offset) |
||
30 | { |
||
31 | return isset($this->data[$offset]); |
||
32 | } |
||
33 | |||
34 | public function offsetUnset($offset) |
||
35 | { |
||
36 | unset($this->data[$offset]); |
||
37 | } |
||
38 | |||
39 | public function toArray() |
||
40 | { |
||
41 | return $this->data; |
||
42 | } |
||
43 | |||
44 | public function count() |
||
45 | { |
||
46 | return count($this->data); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Get a value from the collection using a path syntax to retrieve nested |
||
51 | * data. |
||
52 | * |
||
53 | * @param string $path Path to traverse and retrieve a value from |
||
54 | * |
||
55 | * @return mixed|null |
||
56 | */ |
||
57 | public function getPath($path) |
||
58 | { |
||
59 | return \GuzzleHttp\get_path($this->data, $path); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Set a value into a nested array key. Keys will be created as needed to |
||
64 | * set the value. |
||
65 | * |
||
66 | * @param string $path Path to set |
||
67 | * @param mixed $value Value to set at the key |
||
68 | * |
||
69 | * @throws \RuntimeException when trying to setPath using a nested path |
||
70 | * that travels through a scalar value |
||
71 | */ |
||
72 | public function setPath($path, $value) |
||
73 | { |
||
74 | \GuzzleHttp\set_path($this->data, $path, $value); |
||
75 | } |
||
76 | } |