-
Notifications
You must be signed in to change notification settings - Fork 11
/
AbstractChain.php
75 lines (66 loc) · 1.27 KB
/
AbstractChain.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Cocur\Chain;
use ArrayAccess;
use ArrayIterator;
use IteratorAggregate;
use JsonSerializable;
/**
* Chain.
*
* @author Florian Eckerstorfer
* @copyright 2015-2018 Florian Eckerstorfer
*/
abstract class AbstractChain implements ArrayAccess, IteratorAggregate, JsonSerializable
{
/**
* @var array
*/
public $array = [];
/**
* @return ArrayIterator
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->array);
}
/**
* @param mixed $offset
*
* @return bool
*/
public function offsetExists($offset): bool
{
return isset($this->array[$offset]);
}
/**
* @param mixed $offset
*
* @return mixed
*/
public function offsetGet($offset)
{
return $this->array[$offset];
}
/**
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value): void
{
$this->array[$offset] = $value;
}
/**
* @param mixed $offset
*/
public function offsetUnset($offset): void
{
unset($this->array[$offset]);
}
/**
* @return array
*/
public function jsonSerialize(): array
{
return $this->array;
}
}