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 latitude |
112
|
|
|
* |
113
|
|
|
* @return float Latitude |
114
|
|
|
*/ |
115
|
1 |
|
public function getLatitude() |
116
|
|
|
{ |
117
|
1 |
|
return $this->systemProperties->getLatitude(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set the latitude |
122
|
|
|
* |
123
|
|
|
* @param float $latitude Latitude |
124
|
|
|
* @return SystemProperties Self reference |
125
|
|
|
*/ |
126
|
1 |
|
public function setLatitude($latitude) |
127
|
|
|
{ |
128
|
1 |
|
$this->setSystemProperties($this->systemProperties->setLatitude($latitude)); |
129
|
1 |
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Set the system properties collection |
134
|
|
|
* |
135
|
|
|
* @param SystemProperties $systemProperties System property collection |
136
|
|
|
* @param bool $overwrite Overwrite the existing collection (if present) |
137
|
|
|
*/ |
138
|
1 |
|
protected function setSystemProperties(SystemProperties $systemProperties, $overwrite = false) |
139
|
|
|
{ |
140
|
1 |
|
$this->systemProperties = $systemProperties; |
141
|
1 |
|
$systemPropsState = spl_object_hash($this->systemProperties); |
142
|
|
|
|
143
|
|
|
// If the system property collection state has changed |
144
|
|
|
if (!$overwrite |
145
|
1 |
|
&& !empty($this->collectionStates[SystemProperties::COLLECTION]) |
146
|
1 |
|
&& ($systemPropsState !== $this->collectionStates[SystemProperties::COLLECTION]) |
147
|
1 |
|
) { |
148
|
|
|
// Flag this object as mutated |
149
|
1 |
|
$this->setDirtyState(); |
150
|
1 |
|
} |
151
|
|
|
|
152
|
1 |
|
$this->collectionStates[SystemProperties::COLLECTION] = $systemPropsState; |
153
|
1 |
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Return the longitude |
157
|
|
|
* |
158
|
|
|
* @return float Longitude |
159
|
|
|
*/ |
160
|
1 |
|
public function getLongitude() |
161
|
|
|
{ |
162
|
1 |
|
return $this->systemProperties->getLongitude(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Set the longitude |
167
|
|
|
* |
168
|
|
|
* @param float $longitude Longitude |
169
|
|
|
* @return SystemProperties Self reference |
170
|
|
|
*/ |
171
|
1 |
|
public function setLongitude($longitude) |
172
|
|
|
{ |
173
|
1 |
|
$this->setSystemProperties($this->systemProperties->setLongitude($longitude)); |
174
|
1 |
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Return the elevation |
179
|
|
|
* |
180
|
|
|
* @return float Elevation |
181
|
|
|
*/ |
182
|
1 |
|
public function getElevation() |
183
|
|
|
{ |
184
|
1 |
|
return $this->systemProperties->getElevation(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Set the elevation |
189
|
|
|
* |
190
|
|
|
* @param float $elevation |
191
|
|
|
* @return SystemProperties Self reference |
192
|
|
|
*/ |
193
|
1 |
|
public function setElevation($elevation) |
194
|
|
|
{ |
195
|
1 |
|
$this->setSystemProperties($this->systemProperties->setElevation($elevation)); |
196
|
1 |
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Set the object state to dirty |
201
|
|
|
*/ |
202
|
|
|
abstract protected function setDirtyState(); |
203
|
|
|
} |
204
|
|
|
|