1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Pfilsx\DataGrid\Grid\Items; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Pfilsx\DataGrid\DataGridException; |
8
|
|
|
|
9
|
|
|
abstract class DataGridItem implements DataGridItemInterface |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
protected $data; |
13
|
|
|
protected $identifier; |
14
|
|
|
|
15
|
|
|
public function __construct($data, $identifier = null) |
16
|
|
|
{ |
17
|
|
|
$this->data = $data; |
18
|
|
|
$this->identifier = $identifier; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public final function getData() |
22
|
|
|
{ |
23
|
|
|
return $this->data; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public final function setData($data) |
27
|
|
|
{ |
28
|
|
|
$this->data = $data; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public final function hasIdentifier(): bool |
32
|
|
|
{ |
33
|
|
|
return $this->identifier !== null && $this->has($this->identifier); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public final function getIdentifier() |
37
|
|
|
{ |
38
|
|
|
return $this->identifier; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public final function setIdentifier($identifier) |
42
|
|
|
{ |
43
|
|
|
$this->identifier = $identifier; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Whether a offset exists |
48
|
|
|
* @param string $offset - An offset to check for. |
49
|
|
|
* @return boolean true on success or false on failure. |
50
|
|
|
* The return value will be casted to boolean if non-boolean was returned. |
51
|
|
|
*/ |
52
|
|
|
public final function offsetExists($offset) |
53
|
|
|
{ |
54
|
|
|
return $this->has($offset); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Offset to retrieve |
59
|
|
|
* @param string $offset - The offset to retrieve. |
60
|
|
|
* @return mixed Can return all value types. |
61
|
|
|
*/ |
62
|
|
|
public final function offsetGet($offset) |
63
|
|
|
{ |
64
|
|
|
return $this->get($offset); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Offset to set |
69
|
|
|
* @param string $offset - The offset to assign the value to. |
70
|
|
|
* @param mixed $value - The value to set. |
71
|
|
|
* @return void |
72
|
|
|
* @throws DataGridException |
73
|
|
|
*/ |
74
|
|
|
public final function offsetSet($offset, $value) |
75
|
|
|
{ |
76
|
|
|
throw new DataGridException("Trying to set read-only property: $offset"); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Offset to unset |
81
|
|
|
* @param string $offset - The offset to unset. |
82
|
|
|
* @return void |
83
|
|
|
* @throws DataGridException |
84
|
|
|
*/ |
85
|
|
|
public final function offsetUnset($offset) |
86
|
|
|
{ |
87
|
|
|
throw new DataGridException("Trying to unset read-only property: $offset"); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Magic getter |
92
|
|
|
* @param string $attribute |
93
|
|
|
* @return mixed |
94
|
|
|
*/ |
95
|
|
|
public final function __get(string $attribute) |
96
|
|
|
{ |
97
|
|
|
return $this->get($attribute); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Magic setter |
102
|
|
|
* @param string $attribute |
103
|
|
|
* @param $value |
104
|
|
|
* @throws DataGridException |
105
|
|
|
*/ |
106
|
|
|
public final function __set(string $attribute, $value) |
107
|
|
|
{ |
108
|
|
|
throw new DataGridException("Trying to set read-only property: $attribute"); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Magic unset |
113
|
|
|
* @param string $attribute |
114
|
|
|
* @throws DataGridException |
115
|
|
|
*/ |
116
|
|
|
public final function __unset(string $attribute) |
117
|
|
|
{ |
118
|
|
|
throw new DataGridException("Trying to unset read-only property: $attribute"); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Magic isset |
123
|
|
|
* @param string $attribute |
124
|
|
|
* @return bool |
125
|
|
|
*/ |
126
|
|
|
public function __isset(string $attribute) |
127
|
|
|
{ |
128
|
|
|
return $this->has($attribute); |
129
|
|
|
} |
130
|
|
|
} |