|
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
|
|
|
/** |
|
12
|
|
|
* @template T as AbstractArrayBackedDaftNestedObject |
|
13
|
|
|
* |
|
14
|
|
|
* @template-implements DaftNestedObject<T> |
|
15
|
|
|
* |
|
16
|
|
|
* @property-read int $intNestedLeft |
|
17
|
|
|
* @property-read int $intNestedRight |
|
18
|
|
|
* @property-read int $intNestedLevel |
|
19
|
|
|
* @property-read int $intNestedSortOrder |
|
20
|
|
|
* @property-read scalar[] $daftNestedObjectParentId |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractArrayBackedDaftNestedObject extends AbstractArrayBackedDaftObject implements DaftNestedObject |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @use TraitSortableDaftObject<T> |
|
26
|
|
|
*/ |
|
27
|
|
|
use TraitSortableDaftObject; |
|
28
|
|
|
|
|
29
|
|
|
const COUNT_EXPECT_NON_EMPTY = 0; |
|
30
|
|
|
|
|
31
|
|
|
const SORTABLE_PROPERTIES = [ |
|
32
|
|
|
'intNestedSortOrder', |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
92 |
|
public function GetIntNestedLeft() : int |
|
36
|
|
|
{ |
|
37
|
92 |
|
return NestedTypeParanoia::ForceInt( |
|
38
|
92 |
|
$this->RetrievePropertyValueFromData('intNestedLeft') ?? null |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
92 |
|
public function GetIntNestedRight() : int |
|
43
|
|
|
{ |
|
44
|
92 |
|
return NestedTypeParanoia::ForceInt( |
|
45
|
92 |
|
$this->RetrievePropertyValueFromData('intNestedRight') ?? null |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
92 |
|
public function GetIntNestedLevel() : int |
|
50
|
|
|
{ |
|
51
|
92 |
|
return NestedTypeParanoia::ForceInt( |
|
52
|
92 |
|
$this->RetrievePropertyValueFromData('intNestedLevel') ?? null |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
92 |
|
public function GetIntNestedSortOrder() : int |
|
57
|
|
|
{ |
|
58
|
92 |
|
return NestedTypeParanoia::ForceInt( |
|
59
|
92 |
|
$this->RetrievePropertyValueFromData('intNestedSortOrder') ?? null |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return scalar[] |
|
65
|
|
|
*/ |
|
66
|
92 |
|
public function GetDaftNestedObjectParentId() : array |
|
67
|
|
|
{ |
|
68
|
|
|
/** |
|
69
|
|
|
* @var string[] |
|
70
|
|
|
*/ |
|
71
|
92 |
|
$idProps = static::DaftNestedObjectParentIdProperties(); |
|
72
|
|
|
|
|
73
|
92 |
|
return array_map( |
|
74
|
|
|
/** |
|
75
|
|
|
* @return scalar |
|
76
|
|
|
*/ |
|
77
|
|
|
function (string $prop) { |
|
78
|
|
|
/** |
|
79
|
|
|
* @var scalar |
|
80
|
|
|
*/ |
|
81
|
92 |
|
$out = $this->__get($prop); |
|
82
|
|
|
|
|
83
|
92 |
|
return $out; |
|
84
|
92 |
|
}, |
|
85
|
92 |
|
$idProps |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
2 |
|
public function ChangedProperties() : array |
|
90
|
|
|
{ |
|
91
|
2 |
|
$out = parent::ChangedProperties(); |
|
92
|
|
|
|
|
93
|
2 |
|
$props = array_filter( |
|
94
|
2 |
|
static::DaftNestedObjectParentIdProperties(), |
|
95
|
|
|
function (string $prop) use ($out) : bool { |
|
96
|
2 |
|
return in_array($prop, $out, true); |
|
97
|
2 |
|
} |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
2 |
|
if (count($props) > self::COUNT_EXPECT_NON_EMPTY) { |
|
101
|
2 |
|
$out[] = 'daftNestedObjectParentId'; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
2 |
|
return $out; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|