-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathKeyValueArrayAccess.php
More file actions
57 lines (49 loc) · 1.16 KB
/
KeyValueArrayAccess.php
File metadata and controls
57 lines (49 loc) · 1.16 KB
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
<?php
namespace GT\Input\InputData;
use GT\Input\Input;
use GT\Input\InputData\Datum\InputDatum;
trait KeyValueArrayAccess {
public function offsetExists($offset):bool {
return isset($this->parameters[$offset]);
}
public function offsetGet($offset):mixed {
if($this instanceof FileUploadInputData) {
return $this->getFile($offset);
}
/** @phpstan-ignore-next-line */
elseif(is_a($this, Input::class) || is_a($this, InputData::class)) {
if($this->contains($offset)) {
return $this->get($offset);
}
}
return null;
}
/**
* @param string $offset
* @param string|InputDatum $value
*/
public function offsetSet($offset, $value):void {
if($this->parameters instanceof InputData) {
if(is_string($value)) {
$this->parameters->addKeyValue($offset, $value);
}
else {
$this->parameters->add($offset, $value);
}
}
else {
if(is_string($value)) {
$value = new InputDatum($value);
}
$this->parameters[$offset] = $value;
}
}
public function offsetUnset($offset):void {
if($this->parameters instanceof InputData) {
$this->parameters->remove($offset);
}
else {
unset($this->parameters[$offset]);
}
}
}