1: <?php
2: /**
3: * LICENSE (BSD)
4: *
5: * Copyright (c) 2012, Gerd Christian Kunze
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions are
10: * met:
11: *
12: * * Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: *
15: * * Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: *
19: * * Neither the name of Gerd Christian Kunze nor the names of the
20: * contributors may be used to endorse or promote products derived from
21: * this software without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34: *
35: * Changelog
36: * 30.08.2012 13:47
37: */
38: namespace MOC\Core;
39: use MOC\Api;
40: use MOC\Generic\Device\Core;
41:
42: /**
43: *
44: */
45: class Version implements Core {
46:
47: /** @var int $Release Official Changelog (Only for Major-Changes and Initial-Release */
48: private $Release = 0;
49: /** @var int $Build Internal Changelog (Update-Collection for Official Changelog, Minor Changes) */
50: private $Build = 0;
51: /** @var int $Update Changed Functionality (Add/Remove/Change/Fix-Collection) */
52: private $Update = 0;
53: /** @var int $Fix Correcting Errors (WONT ADD OR REMOVE Functionality) */
54: private $Fix = 0;
55:
56: /**
57: * Get Singleton/Instance
58: *
59: * @static
60: * @return Version
61: */
62: public static function InterfaceInstance() {
63: return new Version();
64: }
65: /**
66: * Get Changelog
67: *
68: * @static
69: * @return \MOC\Core\Changelog
70: */
71: public static function InterfaceChangelog() {
72: return Api::Core()->Changelog()->Create( __CLASS__ );
73: }
74:
75: /**
76: * Get Dependencies
77: *
78: * @static
79: * @return \MOC\Core\Depending
80: */
81: public static function InterfaceDepending() {
82: return Api::Core()->Depending();
83: }
84:
85: /**
86: * Official Changelog
87: *
88: * Only for Major-Changes and Initial-Release
89: *
90: * @param null|int $Number
91: *
92: * @return int|Version
93: */
94: public function Release( $Number = null ) {
95: if( $Number !== null ) {
96: $this->Release = $Number;
97: return $this;
98: } return $this->Release;
99: }
100:
101: /**
102: * Internal Changelog
103: *
104: * Update-Collection for Official Changelog, Minor Changes
105: *
106: * @param null|int $Number
107: *
108: * @return int|Version
109: */
110: public function Build( $Number = null ) {
111: if( $Number !== null ) {
112: $this->Build = $Number;
113: return $this;
114: } return $this->Build;
115: }
116:
117: /**
118: * Changed Functionality
119: *
120: * Add/Remove/Change/Fix-Collection
121: *
122: * @param null|int $Number
123: *
124: * @return int|Version
125: */
126: public function Update( $Number = null ) {
127: if( $Number !== null ) {
128: $this->Update = $Number;
129: return $this;
130: } return $this->Update;
131: }
132:
133: /**
134: * Correcting Errors
135: *
136: * WONT ADD OR REMOVE Functionality
137: *
138: * @param null|int $Number
139: *
140: * @return int|Version
141: */
142: public function Fix( $Number = null ) {
143: if( $Number !== null ) {
144: $this->Fix = $Number;
145: return $this;
146: } return $this->Fix;
147: }
148:
149: /**
150: * Changelog Number
151: *
152: * as String
153: *
154: * @return string
155: */
156: public function Number() {
157: return
158: $this->Release
159: .'.'.
160: $this->Build
161: .'.'.
162: $this->Update
163: .'.'.
164: $this->Fix;
165: }
166:
167: /**
168: * Compare Versions
169: *
170: * true - is newer Changelog
171: * false - is older Changelog
172: * null - both Versions are equal
173: *
174: * @param Version $From
175: * @param Version $To
176: *
177: * @return bool|null
178: */
179: public function Compare( Version $From, Version $To ) {
180: if( $To->Release() - $From->Release() > 0 ) { return true; }
181: if( $To->Release() - $From->Release() < 0 ) { return false; }
182: if( $To->Build() - $From->Build() > 0 ) { return true; }
183: if( $To->Build() - $From->Build() < 0 ) { return false; }
184: if( $To->Update() - $From->Update() > 0 ) { return true; }
185: if( $To->Update() - $From->Update() < 0 ) { return false; }
186: if( $To->Fix() - $From->Fix() > 0 ) { return true; }
187: if( $To->Fix() - $From->Fix() < 0 ) { return false; }
188: return null;
189: }
190: }
191: