|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* apparat-object |
|
5
|
|
|
* |
|
6
|
|
|
* @category Apparat |
|
7
|
|
|
* @package Apparat\Object |
|
8
|
|
|
* @subpackage Apparat\Object\Domain |
|
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
|
10
|
|
|
* @copyright Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
|
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/*********************************************************************************** |
|
15
|
|
|
* The MIT License (MIT) |
|
16
|
|
|
* |
|
17
|
|
|
* Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl |
|
18
|
|
|
* |
|
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
|
21
|
|
|
* the Software without restriction, including without limitation the rights to |
|
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
|
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
|
24
|
|
|
* subject to the following conditions: |
|
25
|
|
|
* |
|
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
27
|
|
|
* copies or substantial portions of the Software. |
|
28
|
|
|
* |
|
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
35
|
|
|
***********************************************************************************/ |
|
36
|
|
|
|
|
37
|
|
|
namespace Apparat\Object\Domain\Model\Object\Traits; |
|
38
|
|
|
|
|
39
|
|
|
use Apparat\Object\Domain\Model\Object\Id; |
|
40
|
|
|
use Apparat\Object\Domain\Model\Object\Revision; |
|
41
|
|
|
use Apparat\Object\Domain\Model\Object\Type; |
|
42
|
|
|
use Apparat\Object\Domain\Model\Properties\SystemProperties; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* System properties trait |
|
46
|
|
|
* |
|
47
|
|
|
* @package Apparat\Object |
|
48
|
|
|
* @subpackage Apparat\Object\Domain |
|
49
|
|
|
* @property array $collectionStates |
|
50
|
|
|
*/ |
|
51
|
|
|
trait SystemPropertiesTrait |
|
52
|
|
|
{ |
|
53
|
|
|
/** |
|
54
|
|
|
* System properties |
|
55
|
|
|
* |
|
56
|
|
|
* @var SystemProperties |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $systemProperties; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Return the object revision |
|
62
|
|
|
* |
|
63
|
|
|
* @return Revision Object revision |
|
64
|
|
|
*/ |
|
65
|
24 |
|
public function getRevision() |
|
66
|
|
|
{ |
|
67
|
24 |
|
return $this->systemProperties->getRevision(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Return the object ID |
|
72
|
|
|
* |
|
73
|
|
|
* @return Id Object ID |
|
74
|
|
|
*/ |
|
75
|
5 |
|
public function getId() |
|
76
|
|
|
{ |
|
77
|
5 |
|
return $this->systemProperties->getId(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Return the object type |
|
82
|
|
|
* |
|
83
|
|
|
* @return Type Object type |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function getType() |
|
86
|
|
|
{ |
|
87
|
1 |
|
return $this->systemProperties->getType(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Return the creation date & time |
|
92
|
|
|
* |
|
93
|
|
|
* @return \DateTimeImmutable Creation date & time |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function getCreated() |
|
96
|
|
|
{ |
|
97
|
1 |
|
return $this->systemProperties->getCreated(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Return the publication date & time |
|
102
|
|
|
* |
|
103
|
|
|
* @return \DateTimeImmutable|null Publication date & time |
|
104
|
|
|
*/ |
|
105
|
1 |
|
public function getPublished() |
|
106
|
|
|
{ |
|
107
|
1 |
|
return $this->systemProperties->getPublished(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Return the language |
|
112
|
|
|
* |
|
113
|
|
|
* @return string Language |
|
114
|
|
|
*/ |
|
115
|
1 |
|
public function getLanguage() |
|
116
|
|
|
{ |
|
117
|
1 |
|
return $this->systemProperties->getLanguage(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Return the latitude |
|
122
|
|
|
* |
|
123
|
|
|
* @return float Latitude |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getLatitude() |
|
126
|
1 |
|
{ |
|
127
|
|
|
return $this->systemProperties->getLatitude(); |
|
128
|
1 |
|
} |
|
129
|
1 |
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Set the latitude |
|
132
|
|
|
* |
|
133
|
|
|
* @param float $latitude Latitude |
|
134
|
|
|
* @return SystemProperties Self reference |
|
135
|
|
|
*/ |
|
136
|
|
|
public function setLatitude($latitude) |
|
137
|
|
|
{ |
|
138
|
1 |
|
$this->setSystemProperties($this->systemProperties->setLatitude($latitude)); |
|
139
|
|
|
return $this; |
|
140
|
1 |
|
} |
|
141
|
1 |
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Set the system properties collection |
|
144
|
1 |
|
* |
|
145
|
1 |
|
* @param SystemProperties $systemProperties System property collection |
|
146
|
1 |
|
* @param bool $overwrite Overwrite the existing collection (if present) |
|
147
|
|
|
*/ |
|
148
|
|
|
protected function setSystemProperties(SystemProperties $systemProperties, $overwrite = false) |
|
149
|
1 |
|
{ |
|
150
|
|
|
$this->systemProperties = $systemProperties; |
|
151
|
|
|
$systemPropsState = spl_object_hash($this->systemProperties); |
|
152
|
1 |
|
|
|
153
|
1 |
|
// If the system property collection state has changed |
|
154
|
|
|
if (!$overwrite |
|
155
|
|
|
&& !empty($this->collectionStates[SystemProperties::COLLECTION]) |
|
156
|
|
|
&& ($systemPropsState !== $this->collectionStates[SystemProperties::COLLECTION]) |
|
157
|
|
|
) { |
|
158
|
|
|
// Flag this object as mutated |
|
159
|
|
|
$this->setDirtyState(); |
|
160
|
1 |
|
} |
|
161
|
|
|
|
|
162
|
1 |
|
$this->collectionStates[SystemProperties::COLLECTION] = $systemPropsState; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Return the longitude |
|
167
|
|
|
* |
|
168
|
|
|
* @return float Longitude |
|
169
|
|
|
*/ |
|
170
|
|
|
public function getLongitude() |
|
171
|
1 |
|
{ |
|
172
|
|
|
return $this->systemProperties->getLongitude(); |
|
173
|
1 |
|
} |
|
174
|
1 |
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Set the longitude |
|
177
|
|
|
* |
|
178
|
|
|
* @param float $longitude Longitude |
|
179
|
|
|
* @return SystemProperties Self reference |
|
180
|
|
|
*/ |
|
181
|
|
|
public function setLongitude($longitude) |
|
182
|
1 |
|
{ |
|
183
|
|
|
$this->setSystemProperties($this->systemProperties->setLongitude($longitude)); |
|
184
|
1 |
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Return the elevation |
|
189
|
|
|
* |
|
190
|
|
|
* @return float Elevation |
|
191
|
|
|
*/ |
|
192
|
|
|
public function getElevation() |
|
193
|
1 |
|
{ |
|
194
|
|
|
return $this->systemProperties->getElevation(); |
|
195
|
1 |
|
} |
|
196
|
1 |
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Set the elevation |
|
199
|
|
|
* |
|
200
|
|
|
* @param float $elevation |
|
201
|
|
|
* @return SystemProperties Self reference |
|
202
|
|
|
*/ |
|
203
|
|
|
public function setElevation($elevation) |
|
204
|
|
|
{ |
|
205
|
|
|
$this->setSystemProperties($this->systemProperties->setElevation($elevation)); |
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Set the object state to dirty |
|
211
|
|
|
*/ |
|
212
|
|
|
abstract protected function setDirtyState(); |
|
213
|
|
|
} |
|
214
|
|
|
|