00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class ErrorHandler extends Object {
00036
00037
00038
00039
00040
00041
00042 var $stdout;
00043
00044
00045
00046
00047
00048
00049 var $stderr;
00050
00051
00052
00053
00054
00055
00056 function __construct($method, $messages) {
00057 $this->stdout = fopen('php:
00058 $this->stderr = fopen('php:
00059 if (Configure::read() > 0 || $method == 'error') {
00060 call_user_func_array(array(&$this, $method), $messages);
00061 } else {
00062 call_user_func_array(array(&$this, 'error404'), $messages);
00063 }
00064 }
00065
00066
00067
00068
00069
00070
00071 function error($params) {
00072 extract($params, EXTR_OVERWRITE);
00073 $this->stderr($code . $name . $message."\n");
00074 $this->_stop();
00075 }
00076
00077
00078
00079
00080
00081
00082 function error404($params) {
00083 extract($params, EXTR_OVERWRITE);
00084 $this->error(array('code' => '404',
00085 'name' => 'Not found',
00086 'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message)));
00087 $this->_stop();
00088 }
00089
00090
00091
00092
00093
00094
00095 function missingController($params) {
00096 extract($params, EXTR_OVERWRITE);
00097 $controllerName = str_replace('Controller', '', $className);
00098 $this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName));
00099 $this->_stop();
00100 }
00101
00102
00103
00104
00105
00106
00107 function missingAction($params) {
00108 extract($params, EXTR_OVERWRITE);
00109 $this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className));
00110 $this->_stop();
00111 }
00112
00113
00114
00115
00116
00117
00118 function privateAction($params) {
00119 extract($params, EXTR_OVERWRITE);
00120 $this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className));
00121 $this->_stop();
00122 }
00123
00124
00125
00126
00127
00128
00129 function missingTable($params) {
00130 extract($params, EXTR_OVERWRITE);
00131 $this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className));
00132 $this->_stop();
00133 }
00134
00135
00136
00137
00138
00139
00140 function missingDatabase($params = array()) {
00141 extract($params, EXTR_OVERWRITE);
00142 $this->stderr(__("Missing Database", true));
00143 $this->_stop();
00144 }
00145
00146
00147
00148
00149
00150
00151 function missingView($params) {
00152 extract($params, EXTR_OVERWRITE);
00153 $this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className));
00154 $this->_stop();
00155 }
00156
00157
00158
00159
00160
00161
00162 function missingLayout($params) {
00163 extract($params, EXTR_OVERWRITE);
00164 $this->stderr(sprintf(__("Missing Layout '%s'", true), $file));
00165 $this->_stop();
00166 }
00167
00168
00169
00170
00171
00172
00173 function missingConnection($params) {
00174 extract($params, EXTR_OVERWRITE);
00175 $this->stderr(__("Missing Database Connection. Try 'cake bake'", true));
00176 $this->_stop();
00177 }
00178
00179
00180
00181
00182
00183
00184 function missingHelperFile($params) {
00185 extract($params, EXTR_OVERWRITE);
00186 $this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector::camelize($helper)));
00187 $this->_stop();
00188 }
00189
00190
00191
00192
00193
00194
00195 function missingHelperClass($params) {
00196 extract($params, EXTR_OVERWRITE);
00197 $this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector::camelize($helper), $file));
00198 $this->_stop();
00199 }
00200
00201
00202
00203
00204
00205
00206 function missingComponentFile($params) {
00207 extract($params, EXTR_OVERWRITE);
00208 $this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector::camelize($component)));
00209 $this->_stop();
00210 }
00211
00212
00213
00214
00215
00216
00217 function missingComponentClass($params) {
00218 extract($params, EXTR_OVERWRITE);
00219 $this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector::camelize($component), $file));
00220 $this->_stop();
00221 }
00222
00223
00224
00225
00226
00227
00228 function missingModel($params) {
00229 extract($params, EXTR_OVERWRITE);
00230 $this->stderr(sprintf(__("Missing model '%s'", true), $className));
00231 $this->_stop();
00232 }
00233
00234
00235
00236
00237
00238
00239
00240 function stdout($string, $newline = true) {
00241 if ($newline) {
00242 fwrite($this->stdout, $string . "\n");
00243 } else {
00244 fwrite($this->stdout, $string);
00245 }
00246 }
00247
00248
00249
00250
00251
00252
00253 function stderr($string) {
00254 fwrite($this->stderr, "Error: ". $string . "\n");
00255 }
00256 }
00257 ?>