1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Core; |
4
|
|
|
|
5
|
|
|
use ArrayAccess; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Row |
9
|
|
|
* @package Coco\SourceWatcher\Core |
10
|
|
|
*/ |
11
|
|
|
class Row implements ArrayAccess, ArrayListAccess |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
private array $attributes; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Row constructor. |
20
|
|
|
* @param array $attributes |
21
|
|
|
*/ |
22
|
|
|
public function __construct ( array $attributes ) |
23
|
|
|
{ |
24
|
|
|
$this->attributes = $attributes; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
public function getAttributes () : array |
31
|
|
|
{ |
32
|
|
|
return $this->attributes; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param array $attributes |
37
|
|
|
*/ |
38
|
|
|
public function setAttributes ( array $attributes ) : void |
39
|
|
|
{ |
40
|
|
|
$this->attributes = $attributes; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
|
|
public function offsetExists ( $offset ) |
47
|
|
|
{ |
48
|
|
|
return array_key_exists( $offset, $this->attributes ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritDoc |
53
|
|
|
*/ |
54
|
|
|
public function offsetGet ( $offset ) |
55
|
|
|
{ |
56
|
|
|
return $this->attributes[$offset]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @inheritDoc |
61
|
|
|
*/ |
62
|
|
|
public function offsetSet ( $offset, $value ) |
63
|
|
|
{ |
64
|
|
|
$this->attributes[$offset] = $value; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritDoc |
69
|
|
|
*/ |
70
|
|
|
public function offsetUnset ( $offset ) |
71
|
|
|
{ |
72
|
|
|
unset( $this->attributes[$offset] ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $key |
77
|
|
|
* @return mixed|null |
78
|
|
|
*/ |
79
|
|
|
public function get ( string $key ) |
80
|
|
|
{ |
81
|
|
|
return $this->attributes[$key] ?? null; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $key |
86
|
|
|
* @param $value |
87
|
|
|
*/ |
88
|
|
|
public function set ( string $key, $value ) : void |
89
|
|
|
{ |
90
|
|
|
$this->attributes[$key] = $value; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $key |
95
|
|
|
*/ |
96
|
|
|
public function remove ( string $key ) : void |
97
|
|
|
{ |
98
|
|
|
unset( $this->attributes[$key] ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param $key |
103
|
|
|
* @return mixed |
104
|
|
|
*/ |
105
|
|
|
public function __get ( $key ) |
106
|
|
|
{ |
107
|
|
|
return $this->attributes[$key]; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param $key |
112
|
|
|
* @param $value |
113
|
|
|
*/ |
114
|
|
|
public function __set ( $key, $value ) |
115
|
|
|
{ |
116
|
|
|
$this->attributes[$key] = $value; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|