Documentation is available at RSDEngineErrorManagerClass.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 RSDEngineErrorManagerClass.
20 *
21 * @package RSDEngine
22 * @author Lukas Feiler <lukas.feiler@chello.at>
23 * @copyright Lukas Feiler 2003
24 * @filesource
25 */
26
27 /**RSDEngineErrorManagerClass extends RSDEngineClass.
28 */
29 require_once('RSDEngine/RSDEngineClass.php');
30
31
32 /**Generates the Application class (the main class) for database backended applications.
33 *
34 * @author Lukas Feiler <lukas.feiler@chello.at>
35 * @version 0.1.9
36 * @copyright Lukas Feiler 2003
37 * @package RSDEngine
38 */
39 class RSDEngineErrorManagerClass extends RSDEngineClass {
40
41 /**Whether to overwrite an existing file. The default for this class is not to do so!
42 * @var boolean
43 */
44 var $overwriteExisting = false;
45
46 /**Returns the class name.
47 *
48 * In fact ucfirst($this->config['projectName']) is returned.
49 * @see config
50 *
51 * @return String The class name.
52 */
53 function getClassName()
54 {
55 return ucfirst($this->config['projectName']) . 'ErrorManager';
56 }
57
58 /**Returns the name for an instance created from this class.
59 *
60 * In fact strtolower($this->config['projectName']) is returned.
61 * @see config
62 *
63 * @return String The instance name.
64 */
65 function getInstanceName()
66 {
67 return strtolower($this->config['projectName']) . 'ErrorManager';
68 }
69
70 /**Returns the code for this class.
71 *
72 * The generated class will be extending RSDApplication.
73 * Note that this method requires $this->config to be correctly
74 * filled with all configuration options of the RSDEngine.
75 * @see config
76 * @see RSDApplication
77 *
78 * @return String The code of the appplication class.
79 */
80 function getCode()
81 {
82 extract($this->config);
83 $className = $this->getClassName();
84 $errorReportRecipient = substr($authors, strpos($authors, '<')+1, strpos($authors, '>') - strpos($authors, '<')-1);
85 $authors = RSArrayUtil::toString(split("\n",$authors),"\n",'* @author %val');
86 $projectNameUC = strtoupper($projectName);
87
88 $write = $this->config['writeErrorManagerClass'];
89 $this->setWrite($write);
90
91 $data = "";
92 $data.= '/' . "**Contains just the class $className.\n" .
93 "*\n" .
94 $authors . "\n" .
95 '* @copyright ' . $copyright . "\n" .
96 '* @package ' . $projectName . "\n" .
97 '* @filesource' . "\n" .
98 '*/' . "\n" .
99 "\n" .
100 '/' . '**' . $className . " extends the class RSErrorManager.\n" .
101 "*/\n" .
102 "require_once('RSErrorManager/RSErrorManager.php');\n" .
103 "\n" .
104 '/' . '**' . $className . ' implements an error management.' . "\n" .
105 '*' . "\n" .
106 $authors . "\n" .
107 '* @copyright ' . $copyright . "\n" .
108 '* @package ' . $projectName . "\n" .
109 '* @version 0.1' . "\n" .
110 '*/' . "\n" .
111 'class ' . $className . ' extends RSErrorManager{' . "\n\n";
112 $paramString = "\$newOperation = '$projectName operation'";
113 $body = ' $this->RSErrorManager($newOperation);' . "\n";
114 $methodComments = ' /' . '**Calls the parent constructor.' . "\n" .
115 ' * @param String $newOperation The current operation - the default value for property \'operation\' of raised errors.' . "\n" .
116 ' */';
117
118 $data .="$methodComments\n" .
119 " function $className($paramString){\n" .
120 $body .
121 ' }' . "\n";
122 $data .="\n" .
123 " /" . "**RSErrorManager:onFatalError is overwritten to customize the reaction on fatal errors.\n" .
124 " */\n" .
125 " function onFatalError(\$pearError){\n";
126 if ($webApplication) {
127 $data .=" \$smarty = new ${projectNameUC}Smarty();\n" .
128 " \$smarty->assign('email', '$errorReportRecipient');\n" .
129 " \$smarty->assign('errorCode', \$pearError->getCode());\n" .
130 " \$smarty->assign('errorMessage', \$pearError->getMessage());\n" .
131 " \$smarty->assign('errorToString', \$pearError->toString());\n" .
132 " \$smarty->display('fatalError.tpl');\n" .
133 " exit;\n";
134 } else {
135 $data .=" die(\$dbError->getMessage());\n";
136 }
137 //end of onDBError
138 $data .=" }\n";
139
140 $data .= <<<END
141
142 /**Handle the occurence of permission-denied errors.
143 *
144 * This method gets called by catch.
145 * @see catch
146 *
147 * @param PEAR_Error \$pearError
148 */
149 function onPermissionDenied(\$pearError)
150 {
151 \$this->reportError(\$pearError);
152 \$smarty = new ${projectNameUC}Smarty();
153 \$smarty->assign('email', '$errorReportRecipient');
154 \$smarty->assign('errorCode', \$pearError->getCode());
155 \$smarty->assign('errorMessage', \$pearError->getMessage());
156 \$smarty->assign('errorToString', \$pearError->toString());
157 \$smarty->display('permissionDenied.tpl');
158 exit;
159 }
160
161 END;;;
162 //end of class
163 $data .= "}";
164 return $data;
165 }
166 }
167 ?>
Documentation generated on Mon, 8 Dec 2003 13:12:45 +0100 by phpDocumentor 1.2.3