Documentation is available at RSDEngineClass.php
1 <?php
2 // RSDEngine: The Rapid and Secure Development Engine
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 /**Contains just the class RSDEngineClass.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**Helper class for generating a class.
28 *
29 * There are two ways of using this class.
30 * The first one is to extend it and to overwrite the methods getClassName,
31 * getInstanceName and getCode. This is recommendable if the class you want to generate
32 * is rather complex. You would call the constructor with only one argument:
33 * <code>
34 *new RSDEngineClassChildClass($config);
35 * </code>
36 * The second way to use this class makes only sense if $config is not needed
37 * for generating your class. Call the constructor like this:
38 * <code>
39 *new RSDEngineClass(false, "MyClass", "myClass", $classCode);
40 * </code>
41 * and use the methods getCode/toRSDFile.
42 *
43 * @author Lukas Feiler <lukas.feiler@chello.at>
44 * @version 0.1.9
45 * @copyright Lukas Feiler 2003
46 * @package RSDEngine
47 */
48 class RSDEngineClass{
49
50 /**An associative array containing all configuration options. Gets set inside the constructor method.
51 * @var Array
52 */
53 var $config = array();
54
55 /**The name of the class to generate. Gets optionally set inside the constructor method.
56 * @var mixed
57 */
58 var $className = false;
59
60 /**The instance name of the class to generate. Gets optionally set inside the constructor method.
61 * @var mixed
62 */
63 var $instanceName = false;
64
65 /**The code of the class to generate. Gets optionally set inside the constructor method.
66 * @var mixed
67 */
68 var $code = false;
69
70 /**Whether to overwrite an existing class file.
71 * @var boolean
72 */
73 var $overwriteExisting = true;
74
75 /**Whether to prevent writing this file.
76 * @var boolean
77 */
78 var $preventWriting = false;
79
80 /**Constructor that does the initialization.
81 *
82 * @see config
83 * @see className
84 * @see instanceName
85 * @see code
86 *
87 * @param Array $config An associative array containing all configuration options.
88 * @param String $className The name of the class to generate.
89 * Passing this argument makes only sense if the method getClassName
90 * does not get overwritten. This argument is optional. The default is false.
91 * @param String $instanceName The instance name of the class to generate.
92 * Passing this argument makes only sense if the method getInstanceName
93 * does not get overwritten. This argument is optional. The default is false.
94 * @param String $code The code of the class to generate.
95 * Passing this argument makes only sense if the method getCode
96 * does not get overwritten. This argument is optional. The default is false.
97 */
98 function RSDEngineClass(&$config, $className = false, $instanceName = false, $code = false)
99 {
100 $this->config =& $config;
101 $this->className = $className;
102 $this->instanceName = $instanceName;
103 $this->code = $code;
104 }
105
106 /**Returns the class name.
107 * @see className
108 * @return String $this->className is returned.
109 */
110 function getClassName()
111 {
112 return $this->className;
113 }
114
115 /**Returns the instance name.
116 * @see instanceName
117 * @return String $this->instanceName is returned.
118 */
119 function getInstanceName()
120 {
121 return $this->instanceName;
122 }
123
124 /**Returns the code for this class.
125 * @see code
126 * @return String $this->code is returned.
127 */
128 function getCode()
129 {
130 return $this->code;
131 }
132
133 /**Sets the properties preventWriting and overwriteExisting based on the string passed as argument
134 * @param String $write 'true', 'false' or 'overwrite.
135 */
136 function setWrite($write)
137 {
138 if ($write == 'false') {
139 $this->preventWriting = true;
140 $this->overwriteExisting = false;
141 } elseif ($write == 'overwrite') {
142 $this->overwriteExisting = true;
143 $this->preventWriting = false;
144 } elseif ($write == 'true') {
145 $this->preventWriting = false;
146 $this->overwriteExisting = false;
147 }
148 }
149
150 /**Returns a new instance of RSDEngineFile.
151 * @return RSDEngineFile Contains just the class code.
152 */
153 function toRSDFile()
154 {
155 $rsdFile =& new RSDEngineFile($this->config, $this->getClassName() . ".php", "<?php\n" . $this->getCode() . "\n?>");
156 $rsdFile->overwriteExisting = $this->overwriteExisting;
157 $rsdFile->preventWriting = $this->preventWriting;
158 return $rsdFile;
159 }
160 }
161 ?>
Documentation generated on Mon, 8 Dec 2003 13:10:44 +0100 by phpDocumentor 1.2.3