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
|
|
|
*/ |
50
|
|
|
trait SystemPropertiesTrait |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* System properties |
54
|
|
|
* |
55
|
|
|
* @var SystemProperties |
56
|
|
|
*/ |
57
|
|
|
protected $systemProperties; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Return the object revision |
61
|
|
|
* |
62
|
|
|
* @return Revision Object revision |
63
|
|
|
*/ |
64
|
20 |
|
public function getRevision() |
65
|
|
|
{ |
66
|
20 |
|
return $this->systemProperties->getRevision(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Return the object ID |
71
|
|
|
* |
72
|
|
|
* @return Id Object ID |
73
|
|
|
*/ |
74
|
5 |
|
public function getId() |
75
|
|
|
{ |
76
|
5 |
|
return $this->systemProperties->getId(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Return the object type |
81
|
|
|
* |
82
|
|
|
* @return Type Object type |
83
|
|
|
*/ |
84
|
1 |
|
public function getType() |
85
|
|
|
{ |
86
|
1 |
|
return $this->systemProperties->getType(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Return the creation date & time |
91
|
|
|
* |
92
|
|
|
* @return \DateTimeImmutable Creation date & time |
93
|
|
|
*/ |
94
|
1 |
|
public function getCreated() |
95
|
|
|
{ |
96
|
1 |
|
return $this->systemProperties->getCreated(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Return the publication date & time |
101
|
|
|
* |
102
|
|
|
* @return \DateTimeImmutable|null Publication date & time |
103
|
|
|
*/ |
104
|
1 |
|
public function getPublished() |
105
|
|
|
{ |
106
|
1 |
|
return $this->systemProperties->getPublished(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Return the object hash |
111
|
|
|
* |
112
|
|
|
* @return string Object hash |
113
|
|
|
*/ |
114
|
1 |
|
public function getHash() |
115
|
|
|
{ |
116
|
1 |
|
return $this->systemProperties->getHash(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Return the latitude |
121
|
|
|
* |
122
|
|
|
* @return float Latitude |
123
|
|
|
*/ |
124
|
1 |
|
public function getLatitude() |
125
|
|
|
{ |
126
|
1 |
|
return $this->systemProperties->getLatitude(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Set the latitude |
131
|
|
|
* |
132
|
|
|
* @param float $latitude Latitude |
133
|
|
|
* @return SystemProperties Self reference |
134
|
|
|
*/ |
135
|
1 |
|
public function setLatitude($latitude) |
136
|
|
|
{ |
137
|
1 |
|
$this->setSystemProperties($this->systemProperties->setLatitude($latitude)); |
138
|
1 |
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Set the system properties collection |
143
|
|
|
* |
144
|
|
|
* @param SystemProperties $systemProperties System property collection |
145
|
|
|
* @param bool $overwrite Overwrite the existing collection (if present) |
146
|
|
|
*/ |
147
|
1 |
|
protected function setSystemProperties(SystemProperties $systemProperties, $overwrite = false) |
148
|
|
|
{ |
149
|
1 |
|
$this->systemProperties = $systemProperties; |
150
|
1 |
|
$systemPropertiesState = spl_object_hash($this->systemProperties); |
151
|
|
|
|
152
|
|
|
// If the system property collection state has changed |
153
|
1 |
|
if (!$overwrite |
154
|
1 |
|
&& !empty($this->collectionStates[SystemProperties::COLLECTION]) |
|
|
|
|
155
|
1 |
|
&& ($systemPropertiesState !== $this->collectionStates[SystemProperties::COLLECTION]) |
156
|
|
|
) { |
157
|
|
|
// Flag this object as mutated |
158
|
1 |
|
$this->setDirtyState(); |
159
|
|
|
} |
160
|
|
|
|
161
|
1 |
|
$this->collectionStates[SystemProperties::COLLECTION] = $systemPropertiesState; |
162
|
1 |
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Return the longitude |
166
|
|
|
* |
167
|
|
|
* @return float Longitude |
168
|
|
|
*/ |
169
|
1 |
|
public function getLongitude() |
170
|
|
|
{ |
171
|
1 |
|
return $this->systemProperties->getLongitude(); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Set the longitude |
176
|
|
|
* |
177
|
|
|
* @param float $longitude Longitude |
178
|
|
|
* @return SystemProperties Self reference |
179
|
|
|
*/ |
180
|
1 |
|
public function setLongitude($longitude) |
181
|
|
|
{ |
182
|
1 |
|
$this->setSystemProperties($this->systemProperties->setLongitude($longitude)); |
183
|
1 |
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Return the elevation |
188
|
|
|
* |
189
|
|
|
* @return float Elevation |
190
|
|
|
*/ |
191
|
|
|
public function getElevation() |
192
|
|
|
{ |
193
|
|
|
return $this->systemProperties->getElevation(); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Set the elevation |
198
|
|
|
* |
199
|
|
|
* @param float $elevation |
200
|
|
|
* @return SystemProperties Self reference |
201
|
|
|
*/ |
202
|
1 |
|
public function setElevation($elevation) |
203
|
|
|
{ |
204
|
1 |
|
$this->setSystemProperties($this->systemProperties->setElevation($elevation)); |
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Set the object state to dirty |
210
|
|
|
*/ |
211
|
|
|
abstract protected function setDirtyState(); |
212
|
|
|
} |
213
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: