1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Base daft nested objects. |
4
|
|
|
* |
5
|
|
|
* @author SignpostMarv |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace SignpostMarv\DaftObject; |
10
|
|
|
|
11
|
|
|
abstract class AbstractArrayBackedDaftNestedObject extends AbstractArrayBackedDaftObject implements DaftNestedObject |
12
|
|
|
{ |
13
|
|
|
const COUNT_EXPECT_NON_EMPTY = 0; |
14
|
|
|
|
15
|
|
|
const SORTABLE_PROPERTIES = [ |
16
|
|
|
'intNestedSortOrder', |
17
|
|
|
]; |
18
|
|
|
|
19
|
120 |
|
public function GetIntNestedLeft() : int |
20
|
|
|
{ |
21
|
120 |
|
return NestedTypeParanoia::ForceInt( |
22
|
120 |
|
$this->RetrievePropertyValueFromData('intNestedLeft') ?? null |
23
|
|
|
); |
24
|
|
|
} |
25
|
|
|
|
26
|
120 |
|
public function GetIntNestedRight() : int |
27
|
|
|
{ |
28
|
120 |
|
return NestedTypeParanoia::ForceInt( |
29
|
120 |
|
$this->RetrievePropertyValueFromData('intNestedRight') ?? null |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
120 |
|
public function GetIntNestedLevel() : int |
34
|
|
|
{ |
35
|
120 |
|
return NestedTypeParanoia::ForceInt( |
36
|
120 |
|
$this->RetrievePropertyValueFromData('intNestedLevel') ?? null |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
120 |
|
public function GetIntNestedSortOrder() : int |
41
|
|
|
{ |
42
|
120 |
|
return NestedTypeParanoia::ForceInt( |
43
|
120 |
|
$this->RetrievePropertyValueFromData('intNestedSortOrder') ?? null |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
62 |
|
public function ObtainDaftNestedObjectParentId() : array |
48
|
|
|
{ |
49
|
|
|
/** |
50
|
|
|
* @var string[] |
51
|
|
|
*/ |
52
|
62 |
|
$idProps = static::DaftNestedObjectParentIdProperties(); |
53
|
|
|
|
54
|
62 |
|
return array_map( |
55
|
|
|
/** |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
|
|
function (string $prop) { |
59
|
62 |
|
return $this->__get($prop); |
60
|
62 |
|
}, |
61
|
62 |
|
$idProps |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
116 |
|
public function SetIntNestedLeft(int $value) : void |
66
|
|
|
{ |
67
|
116 |
|
if ( ! TypeParanoia::IsThingStrings(static::class, DaftNestedWriteableObject::class)) { |
68
|
2 |
|
throw new ClassDoesNotImplementClassException( |
69
|
2 |
|
static::class, |
70
|
2 |
|
DaftNestedWriteableObject::class |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
114 |
|
$this->NudgePropertyValue('intNestedLeft', $value); |
75
|
114 |
|
} |
76
|
|
|
|
77
|
116 |
|
public function SetIntNestedRight(int $value) : void |
78
|
|
|
{ |
79
|
116 |
|
if ( ! TypeParanoia::IsThingStrings(static::class, DaftNestedWriteableObject::class)) { |
80
|
2 |
|
throw new ClassDoesNotImplementClassException( |
81
|
2 |
|
static::class, |
82
|
2 |
|
DaftNestedWriteableObject::class |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
114 |
|
$this->NudgePropertyValue('intNestedRight', $value); |
87
|
114 |
|
} |
88
|
|
|
|
89
|
66 |
|
public function SetIntNestedLevel(int $value) : void |
90
|
|
|
{ |
91
|
66 |
|
if ( ! TypeParanoia::IsThingStrings(static::class, DaftNestedWriteableObject::class)) { |
92
|
2 |
|
throw new ClassDoesNotImplementClassException( |
93
|
2 |
|
static::class, |
94
|
2 |
|
DaftNestedWriteableObject::class |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
64 |
|
$this->NudgePropertyValue('intNestedLevel', $value); |
99
|
64 |
|
} |
100
|
|
|
|
101
|
34 |
|
public function SetIntNestedSortOrder(int $value) : void |
102
|
|
|
{ |
103
|
34 |
|
if ( ! TypeParanoia::IsThingStrings(static::class, DaftNestedWriteableObject::class)) { |
104
|
2 |
|
throw new ClassDoesNotImplementClassException( |
105
|
2 |
|
static::class, |
106
|
2 |
|
DaftNestedWriteableObject::class |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
32 |
|
$this->NudgePropertyValue('intNestedSortOrder', $value); |
111
|
32 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param mixed $value |
115
|
|
|
*/ |
116
|
62 |
|
public function AlterDaftNestedObjectParentId($value) : void |
117
|
|
|
{ |
118
|
62 |
|
if ( ! TypeParanoia::IsThingStrings(static::class, DaftNestedWriteableObject::class)) { |
119
|
2 |
|
throw new ClassDoesNotImplementClassException( |
120
|
2 |
|
static::class, |
121
|
2 |
|
DaftNestedWriteableObject::class |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @var string[] |
127
|
|
|
*/ |
128
|
62 |
|
$props = static::DaftNestedObjectParentIdProperties(); |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @var array<string, scalar|array|object|null> |
132
|
|
|
*/ |
133
|
62 |
|
$propsAndVals = array_combine($props, (is_array($value) ? $value : [$value])); |
134
|
|
|
|
135
|
62 |
|
foreach ($propsAndVals as $prop => $val) { |
136
|
62 |
|
$this->NudgePropertyValue($prop, $val); |
137
|
|
|
} |
138
|
62 |
|
} |
139
|
|
|
|
140
|
2 |
|
public function ChangedProperties() : array |
141
|
|
|
{ |
142
|
2 |
|
$out = parent::ChangedProperties(); |
143
|
|
|
|
144
|
2 |
|
$props = array_filter( |
145
|
2 |
|
static::DaftNestedObjectParentIdProperties(), |
146
|
|
|
function (string $prop) use ($out) : bool { |
147
|
2 |
|
return TypeParanoia::MaybeInArray($prop, $out); |
148
|
2 |
|
} |
149
|
|
|
); |
150
|
|
|
|
151
|
2 |
|
if (count($props) > self::COUNT_EXPECT_NON_EMPTY) { |
152
|
2 |
|
$out[] = 'daftNestedObjectParentId'; |
153
|
|
|
} |
154
|
|
|
|
155
|
2 |
|
return $out; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|