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