Repository navigation
Expand file tree
/
Copy pathArrayProperty.php
More file actions
119 lines (102 loc) · 3.23 KB
/
Copy pathArrayProperty.php
File metadata and controls
119 lines (102 loc) · 3.23 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
declare(strict_types=1);
namespace NeoVg\Struct\StructProperty;
/**
* Class ArrayStructProperty
*/
class ArrayProperty extends DefaultProperty
{
####################################################################################################################
# Value
####################################################################################################################
/**
* @param mixed $value
*
* @return DefaultProperty
* @throws \TypeError
*/
public function setValue($value): DefaultProperty
{
$this->_checkTypes($value);
$this->_value = $value;
$this->_isSet = true;
$this->_isDirty = true;
return $this;
}
####################################################################################################################
# Dirty State
####################################################################################################################
/**
* @return $this
*/
public function setClean(): DefaultProperty
{
$this->_isDirty = false;
return $this;
}
####################################################################################################################
# Types
####################################################################################################################
/**
* @param int|string $key
* @param $value
*
* @return
* @throws \TypeError
*/
public function checkValue($key, $value)
{
if (!$this->_isOfValidType($value)) {
throw new \TypeError(sprintf('Key %s in argument 1 passed to %s::%s() must be of type %s, %s given',
$key,
static::class,
$this->_name,
$this->_type,
gettype($value)
));
}
return $value;
}
/**
* @param $values
*
* @throws \TypeError
*/
protected function _checkTypes($values): void
{
if ($values === null) {
return;
}
if (!is_array($values)) {
throw new \TypeError(sprintf('Argument 1 passed to %s::%s() must be of type %s[], %s given',
static::class,
$this->_name,
$this->_type,
gettype($values)
));
}
foreach (array_keys($values) as $key) {
if (!$this->_isOfValidType($values[$key])) {
throw new \TypeError(sprintf('Key %s in argument 1 passed to %s::%s() must be of type %s, %s given',
$key,
static::class,
$this->_name,
$this->_type,
gettype($values[$key])
));
}
}
}
####################################################################################################################
# Debug
####################################################################################################################
/**
* @return array
*/
public function __debugInfo()
{
return parent::__debugInfo() + [
'[containsArray]' => true,
];
}
}