Documentation is available at EVS.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 /**To be passed to some methods of classes of the EVS project if you do not wish versioning to be applied.
29 */
30 DEFINE('EVS_NO_VERSIONING',false);
31
32 /**Needed for the management of projects.
33 */
34 require_once('EVS/EVSProject.php');
35
36 /**EVS uses the error codes defined in RSErrorManager.php.
37 */
38 require_once('RSErrorManager/RSErrorManager.php');
39
40 /**PEAR::File for various IO operations
41 */
42 require_once("File.php");
43
44 /**PEAR::Validate not at all required.
45 */
46 require_once("Validate.php");
47
48 /**PEAR::SearchReplace for replaceing %%PROJECT_NAME%% in some skel files.
49 */
50 require_once("File/SearchReplace.php");
51
52 /**RocketScience::RSIO for copying a directory structure
53 */
54 require_once('RSIO/RSIO.php');
55
56 /**RocketScience::RSValidation string validation
57 */
58 require_once('RSValidation/RSValidation.php');
59
60 /**The RSDEngine is used to generate php code for database assecces based on the SQL DDL if provided.
61 */
62 require_once('RSDEngine/RSDEngine.php');
63
64 /**Implements the creation and management of different EVSProjects.
65 *
66 * EVS provides:
67 * Coding standards.<br>
68 * Unified design model for all applications: MVC. <br>
69 * An evnrironment that makes it easyer to manage the development, testing and documentation of different applications. <br>
70 * A collection of powerful classes for faster application development. <br>
71 * The RSDEngine - the Rapid and Secure Development Engine for generating code from your database desing.<br>
72 *
73 * @author Lukas Feiler <lukas.feiler@chello.at>
74 * @version 0.1.9
75 * @copyright Lukas Feiler 2003
76 * @package EVS
77 */
78 class EVS {
79
80 /**Holds all projects as instances of EVSProject. Gets filled by loadProjects.
81 * @see loadProjects.
82 * @var Array
83 */
84 var $projects = array();
85
86 /**An associative array holding the default values for new projects.
87 *
88 * This property is set inside the constcructor method.
89 * @see EVS::EVS
90 * @var Array An associative array.
91 */
92 var $defaults = array();
93
94 /**The path where EVS is installed.
95 * @var String A path name without a trailing slash.
96 */
97 var $_root = '';
98
99
100 /**Constructor method.
101 *
102 * Sets $this->_root and $this->defaults.
103 * @see _root
104 * @see defaults
105 * @param String $root The path where EVS is installed.
106 * @param Array $defaults An associative array holding the default values for new projects.
107 */
108 function EVS($root, $defaults)
109 {
110 $this->_root = $root;
111 $this->defaults = $defaults;
112 }
113
114 /**Returns a new instance of EVSProject.
115 *
116 * @see EVSProject
117 * @param String $projectName The name of the project.
118 * @return mixed An instance of EVSProject or if the project does not exist false.
119 */
120 function &getProject($projectName)
121 {
122 if (!$this->projectExists($projectName)) {
123 return false;
124 }
125 return new EVSProject($this, $projectName);
126 }
127
128 /**Loads all projects as instances of EVSProject into $this->projects.
129 *
130 * @see projects
131 */
132 function loadProjects()
133 {
134 $this->projects = array();
135 $startDir = "$this->_root/projects";
136 $handle=opendir($startDir);
137 while (($file = readdir($handle))!==false) {
138 if (($file != ".") && ($file != "..")) {
139 $dirName = $file;
140 $file = "$startDir/$dirName";
141 if (is_dir($file)) {
142 $this->projects[] =& new EVSProject($this, $dirName);
143 }
144 }
145 }
146 }
147
148 /**Returns true if the project exists.
149 *
150 * @param String $name The name of the project.
151 * @return boolean True if the project exists, false otherwise.
152 */
153 function projectExists($name)
154 {
155 return file_exists($this->getRoot() . "/projects/$name");
156 }
157
158 /**Returns the root of the EVS directory structure.
159 *
160 * In fact $this->_root is just returned.
161 * @see _root
162 * @return String Absolute path to the root directory of EVS.
163 */
164 function getRoot()
165 {
166 return $this->_root;
167 }
168
169 /**Returns an absolute path to the skel (skeleton) where all files for a version are stored.
170 * @return String Absolute path to the skel.
171 */
172 function getVersionSkel()
173 {
174 return $this->getRoot() . '/version_skel';
175 }
176
177 /**Returns an absolute path to the skel (skeleton) where all files for a version that was defined as an web application are stored.
178 * @return String Absolute path to the web application skel.
179 */
180 function getVersionWebApplicationSkel()
181 {
182 return $this->getRoot() . '/version_skel_webapp';
183 }
184
185 /**Returns an absolute path to the skel (skeleton) where all files for a new project are stored.
186 * @return String Absolute path to the project skel.
187 */
188 function getProjectSkel()
189 {
190 return $this->getRoot() . '/project_skel';
191 }
192
193 /**Creates a new project and returns a new EVSProject.
194 *
195 * @param String $projectName The name of the project to create.
196 * @param String $versioning If you do not want versioning support for this project pass an empty string otherwise a non-empty.
197 * @return mixed A new instance of EVSProject on success or an instance of RSError on failure.
198 */
199 function &createProject($projectName, $versioning)
200 {
201 if (!RSValidation::isAlphanumericIncludingUnderscore($projectName)) {
202 return RSErrorManager::raiseRSError('EVS', 'project name', 'createProject', 'The project name may only contain alphanumeric characters and underscores.', RSERROR_INVALID);
203 }
204 if ($this->projectExists($projectName)) {
205 return RSErrorManager::raiseRSError('EVS', 'project name', 'createProject', "A project named $projectName already exists.", RSERROR_INVALID);
206 }
207 if (mkdir($this->getRoot() . "/projects/$projectName")) {
208 if ($versioning) {
209 RSIO::copyDirectory($this->getProjectSkel() . "/", $this->getRoot() . "/projects/$projectName/", RSIO_NO_OVERWRITE);
210 }
211
212 //write projectName
213 $data = "[project]\n";
214 if ($projectName) {
215 $data .= "projectName = $projectName\n";
216 }
217 if ($versioning) {
218 $data .= "versioning = $versioning";
219 }
220 File::write($this->getRoot() . "/projects/$projectName/config.ini", $data, FILE_MODE_WRITE);
221
222 return new EVSProject($this, $projectName);
223 }else{
224 return RSErrorManager::raiseRSError('EVS', 'project', 'createProject', "The creation of the project $projectName failed.", RSERROR_OPERATION_FAILED);
225 }
226 }
227 }
228 ?>
Documentation generated on Mon, 8 Dec 2003 13:10:30 +0100 by phpDocumentor 1.2.3