Documentation is available at EVSProject.php
1 <?php
2 // EVS: Easy Versioning System
3 // Copyright (C) 2003 Lukas Feiler
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 /**This file is part of EVS - Easy Versioning System.
20 *
21 * @author Lukas Feiler <lukas.feiler@chello.at>
22 * @version 0.1.9
23 * @copyright Lukas Feiler 2003
24 * @package EVS
25 * @filesource
26 */
27
28 /**Needed for managing the different versions of a project.
29 */
30 require_once('EVS/EVSVersion.php');
31
32 /**Implements the management of different EVSVersions.
33 *
34 * @author Lukas Feiler <lukas.feiler@chello.at>
35 * @version 0.1.9
36 * @copyright Lukas Feiler 2003
37 * @package EVS
38 */
39 class EVSProject {
40
41 /**An instance of EVS. Gets set inside the costructor method.
42 * @see EVSProject::EVSProject
43 * @var EVS
44 */
45 var $evs = null;
46
47 /**The absolute path to the directory where the project is stored. Gets set inside the costructor method.
48 * @see EVSProject::EVSProject
49 * @var String
50 */
51 var $projectDirectory = '';
52
53 /**If this project supports versioning project or not. Gets set inside the costructor method.
54 * @see EVSProject::EVSProject
55 * @var boolean
56 */
57 var $versioning = true;
58
59 /**An array containing all versions of the project as instances of EVSVersion (sorted by version number).
60 * @var Array
61 */
62 var $versions = array();
63
64 /**An array containing all releases of the project as instances of EVSVersion (sorted by release number).
65 * @var Array
66 */
67 var $releases = array();
68
69 /**The project name. Is set inside the constructor method.
70 * @var String
71 */
72 var $name;
73
74 /**The latest development release. Is set in the constructor.
75 * @var EVSVersion
76 */
77 var $latestDevelopmentRelease;
78
79 /**The latest stable release. Is set inside the constructor method.
80 * @var EVSVersion
81 */
82 var $latestStableRelease;
83
84 /**The latest current development version. Is set inside the constructor method.
85 * @var EVSVersion
86 */
87 var $latestCurrentDevelopmentVersion;
88
89 /**The latest current stable version. Is set inside the constructor method.
90 * @var EVSVersion
91 */
92 var $latestCurrentStableVersion;
93
94 /**The latest current version. Is set inside the constructor method.
95 * @var EVSVersion
96 */
97 var $latestCurrentVersion;
98
99
100 /**Construtor method.
101 *
102 * Loads all versions of this project and sets the properties of this EVSProject instance.
103 *
104 */
105 function EVSProject(&$evs, $projectName)
106 {
107 $this->evs =& $evs;
108 $this->projectDirectory = $this->evs->getRoot() . "/projects/$projectName";
109
110 $config = array();
111 if (file_exists("$this->projectDirectory/config.ini")) {
112 $config = parse_ini_file("$this->projectDirectory/config.ini");
113 }
114 if (isset($config['versioning'])) {
115 $this->versioning = $config['versioning'];
116 } else {
117 $this->versioning = false;
118 }
119 $this->name = $config['projectName'] != "" ? $config['projectName'] : $projectName;
120
121 $this->_loadVersions();
122
123 if ($this->versioning) {
124 $this->latestStableRelease = $this->getLatestStableRelease();
125 $this->latestDevelopmentRelease = $this->getLatestDevelopmentRelease();
126 $this->latestCurrentDevelopmentVersion = $this->getLatestCurrentDevelopmentVersion();
127 $this->latestCurrentStableVersion = $this->getLatestCurrentStableVersion();
128 $this->latestCurrentVersion = $this->getLatestCurrentVersion();
129 }
130 }
131
132 /**Fills the arrays $this->versions and $this->releases with instances of EVSVersion.
133 *
134 * $this->version and $this->releases get sored by the private method _versionSortCompare.
135 * @see _versionSortCompare
136 * @access private
137 */
138 function _loadVersions()
139 {
140 $this->versions = array();
141
142 if ($this->versioning) {
143 $handle=opendir($this->projectDirectory);
144 while (($file = readdir($handle))!==false) {
145 if (($file != ".") && ($file != "..")) {
146 if (is_dir("$this->projectDirectory/$file")) {
147 //if is in the format [one or more numbers].[one or more numbers].current or
148 //[one or more numbers].[one or more numbers].[one or more numbers]
149 if (preg_match("/^[0-9]{1,}\.[0-9]{1,}\.(current|[0-9]{1,})$/", $file)) {
150 $version =& new EVSVersion($this, $file);
151 $this->versions[] =& $version;
152 if ($version->isRelease) {
153 $this->releases[] =& $version;
154 }
155 }
156 }
157 }
158 }
159 usort($this->versions,array('EVSProject', '_versionSortCompare'));
160 usort($this->releases,array('EVSProject', '_versionSortCompare'));
161
162 for ($i=0;$i<count($this->versions);$i++) {
163 $this->versions[$i]->init();
164 }
165 } else {
166 $this->versions[] =& new EVSVersion($this, EVS_NO_VERSIONING);
167 }
168 }
169
170 /**Returns the version specified by the version number passed as argument.
171 *
172 * Note that this method only looks in the array $this->versions.
173 *
174 * @param mixed $version The version number or the boolean value false if you just want the first version (which is the case if version support has been disabled for this project and therefore only one version exists). This argument is optional. The default is false.
175 * @return mixed An instance of EVSVersion or false if no such method exists.
176 */
177 function getVersion($version = false)
178 {
179 if ($version) {
180 for ($i = 0; $i < count($this->versions); $i++) {
181 if ($this->versions[$i]->version == $version) {
182 return $this->versions[$i];
183 }
184 }
185 } else {
186 if (count($this->versions) > 0) {
187 return $this->versions[0];
188 }
189 }
190 return false;
191 }
192
193 /**Returns the latest stable release.
194 *
195 * @return mixed If there are stable releases the latest will be returned as an instance of EVSVersion - if there aren't any stable releases the boolean value false is returned.
196 */
197 function getLatestStableRelease()
198 {
199 for ($i=count($this->releases)-1;$i>=0;$i--) {
200 $release = $this->releases[$i];
201 if ($release->isStableVersion) {
202 return $release;
203 }
204 }
205 return false;
206 }
207
208 /**Returns the latest development release.
209 *
210 * @return mixed If there are development releases the latest will be returned as an instance of EVSVersion - if there aren't any development releases the boolean value false is returned.
211 */
212 function getLatestDevelopmentRelease()
213 {
214 for ($i = count($this->releases) - 1; $i >= 0; $i--) {
215 $release = $this->releases[$i];
216 if ($release->isDevelopmentVersion) {
217 return $release;
218 }
219 }
220 }
221
222 /**Returns the latest current development version.
223 *
224 * @return mixed If there are current development versions the latest will be returned as an instance of EVSVersion - if there are, not false will be returned.
225 */
226 function getLatestCurrentDevelopmentVersion()
227 {
228 for ($i = count($this->versions) - 1; $i >= 0; $i--) {
229 $version = $this->versions[$i];
230 if ($version->isCurrentVersion && $version->isDevelopmentVersion) {
231 return $version;
232 }
233 }
234 return false;
235 }
236
237 /**Returns the latest current stable version.
238 *
239 * @return mixed If there are current stable versions the latest will be returned as an instance of EVSVersion - if there are not, false will be returned.
240 */
241 function getLatestCurrentStableVersion()
242 {
243 for ($i = count($this->versions) - 1; $i >= 0; $i--) {
244 $version = $this->versions[$i];
245 if ($version->isCurrentVersion && $version->isStableVersion) {
246 return $version;
247 }
248 }
249 }
250
251 /**Returns the latest current version.
252 *
253 * @return mixed If there are current versions the latest will be returned as an instance of EVSVersion - if there are not, false will be returned.
254 */
255 function getLatestCurrentVersion()
256 {
257 for ($i = count($this->versions) - 1; $i >= 0; $i--) {
258 $version = $this->versions[$i];
259 if ($version->isCurrentVersion) {
260 return $version;
261 }
262 }
263 }
264
265 /**Returns the latest patchlevel version in the branch "$major.$minor".
266 *
267 * @return mixed If there are releases in the branch "$major.$minor" the latest will be returned as an instance of EVSVersion - if there are not, false will be returned.
268 */
269 function getLatestPatchlevelVersion($major, $minor)
270 {
271 for ($i = count($this->versions) - 1; $i >= 0; $i--) {
272 $version = $this->versions[$i];
273 if ($version->isRelease && $version->major == $major && $version->minor == $minor) {
274 return $version;
275 }
276 }
277 return false;
278 }
279
280
281 /**Method used to sort the versions of the project by release number.
282 *
283 * This method is used by _loadVersions. It is passed to usort to perform a user defined sorting.
284 * @see _loadVersions
285 *
286 * @access private
287 * @param EVSVersion $o1;
288 * @param EVSVersion $o2;
289 * @return int An integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
290 */
291 function _versionSortCompare($o1, $o2)
292 {
293 $a = $o1->version;
294 $b = $o2->version;
295 $versions1 = split('\.',$a);
296 $major1 = $versions1[0];
297 $minor1 = $versions1[1];
298 $patchlevel1 = $versions1[2];
299
300 $versions2 = split('\.',$b);
301 $major2 = $versions2[0];
302 $minor2 = $versions2[1];
303 $patchlevel2 = $versions2[2];
304
305 if ($major1 * 1 < $major2 * 1) {
306 return -1;
307 }
308 if ($major1 * 1 > $major2 * 1) {
309 return 1;
310 }
311 if ($minor1 * 1 < $minor2 * 1) {
312 return -1;
313 }
314 if ($minor1 * 1 > $minor2 * 1) {
315 return 1;
316 }
317
318 if ($patchlevel1 != $patchlevel2) {
319 if($patchlevel1 == 'current') return 1;
320 if($patchlevel2 == 'current') return -1;
321 }
322
323 if ($patchlevel1 * 1 < $patchlevel2 * 1) {
324 return -1;
325 }
326 if ($patchlevel1 * 1 > $patchlevel2 * 1) {
327 return 1;
328 }
329 return 0;
330 }
331
332 /**Create a directory for the new version and returns a new EVSVersion for it.
333 *
334 * This method is only called right after creating a project.
335 * If the value passed as argument evaluates to true, a 'real'
336 * version will be created. If it evaluates to false a version
337 * will only be faked. This is needed when the project was created with
338 * versionining support disabled. In this case no subdirectory will get created and
339 * $this->versions holds only one instance of EVSVersion.
340 * @param mixed $version The version number to create or the boolean value false.
341 */
342 function &createVersion($version)
343 {
344 if ($version) {
345 if (!mkdir("$this->projectDirectory/$version")) {
346 return RSErrorManager::raiseRSError('EVSProject', '', 'createVersion', "Could not create a new directory for version $version.", RSERROR_OPERATION_FAILED);
347 }
348 }
349 return new EVSVersion($this, $version);
350 }
351 }
352 ?>
Documentation generated on Mon, 8 Dec 2003 13:10:33 +0100 by phpDocumentor 1.2.3