Completed
Push — master ( c2a4dc...f4221b )
by Joschi
03:32
created

SystemPropertiesTrait::setDirtyState()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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