|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* components |
|
4
|
|
|
* |
|
5
|
|
|
* @author Wolfy-J |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace Spiral\ODM\Accessors; |
|
8
|
|
|
|
|
9
|
|
|
use Spiral\Models\Traits\SolidStateTrait; |
|
10
|
|
|
use Spiral\ODM\CompositableInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Provides ability to perform scalar operations on arrays. |
|
14
|
|
|
*/ |
|
15
|
|
|
class AbstractArray implements CompositableInterface, \Countable |
|
16
|
|
|
{ |
|
17
|
|
|
use SolidStateTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $values = []; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Indication that values were updated. |
|
26
|
|
|
* |
|
27
|
|
|
* @var bool |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $updated = false; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Low level atomic operations. |
|
33
|
|
|
* |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $atomics = []; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param mixed $values |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct($values) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->setValue($values); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function setValue($data) |
|
50
|
|
|
{ |
|
51
|
|
|
// TODO: Implement setValue() method. |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function hasUpdates(): bool |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->updated; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function buildAtomics(string $container = ''): array |
|
66
|
|
|
{ |
|
67
|
|
|
// TODO: Implement buildAtomics() method. |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
public function flushUpdates() |
|
74
|
|
|
{ |
|
75
|
|
|
// TODO: Implement flushUpdates() method. |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return array |
|
80
|
|
|
*/ |
|
81
|
|
|
public function packValue() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->values; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return int |
|
88
|
|
|
*/ |
|
89
|
|
|
public function count(): int |
|
90
|
|
|
{ |
|
91
|
|
|
return count($this->values); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Clone accessor and ensure that it state is updated. |
|
96
|
|
|
*/ |
|
97
|
|
|
public function __clone() |
|
98
|
|
|
{ |
|
99
|
|
|
//Every cloned accessor must become solid and updated |
|
100
|
|
|
$this->solidState = true; |
|
101
|
|
|
$this->updated = true; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return array |
|
106
|
|
|
*/ |
|
107
|
|
|
public function __debugInfo() |
|
108
|
|
|
{ |
|
109
|
|
|
return [ |
|
110
|
|
|
'values' => $this->packValue(), |
|
111
|
|
|
'atomics' => $this->buildAtomics('@scalarArray'), |
|
112
|
|
|
]; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @return array |
|
117
|
|
|
*/ |
|
118
|
|
|
public function jsonSerialize() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->packValue(); |
|
121
|
|
|
} |
|
122
|
|
|
} |