1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: App::import('Controller', 'App');
27: 28: 29: 30: 31: 32: 33: 34:
35: class CakeErrorController extends AppController {
36: var $name = 'CakeError';
37: 38: 39: 40: 41:
42: var $uses = array();
43: 44: 45: 46: 47: 48:
49: function __construct() {
50: parent::__construct();
51: $this->_set(Router::getPaths());
52: $this->params = Router::getParams();
53: $this->constructClasses();
54: $this->Component->initialize($this);
55: $this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
56: }
57: }
58: 59: 60: 61: 62: 63: 64: 65: 66: 67:
68: class ErrorHandler extends Object {
69: 70: 71: 72: 73: 74:
75: var $controller = null;
76: 77: 78: 79: 80: 81:
82: function __construct($method, $messages) {
83: App::import('Core', 'Sanitize');
84: static $__previousError = null;
85:
86: if ($__previousError != array($method, $messages)) {
87: $__previousError = array($method, $messages);
88: $this->controller =& new CakeErrorController();
89: } else {
90: $this->controller =& new Controller();
91: $this->controller->viewPath = 'errors';
92: }
93:
94: $options = array('escape' => false);
95: $messages = Sanitize::clean($messages, $options);
96:
97: if (!isset($messages[0])) {
98: $messages = array($messages);
99: }
100:
101: if (method_exists($this->controller, 'apperror')) {
102: return $this->controller->appError($method, $messages);
103: }
104:
105: if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($this)))) {
106: $method = 'error';
107: }
108:
109: if ($method !== 'error') {
110: if (Configure::read() == 0) {
111: $method = 'error404';
112: if (isset($code) && $code == 500) {
113: $method = 'error500';
114: }
115: }
116: }
117: $this->dispatchMethod($method, $messages);
118: $this->_stop();
119: }
120: 121: 122: 123: 124: 125:
126: function error($params) {
127: extract($params, EXTR_OVERWRITE);
128: $this->controller->set(array(
129: 'code' => $code,
130: 'name' => $name,
131: 'message' => $message,
132: 'title' => $code . ' ' . $name
133: ));
134: $this->_outputMessage('error404');
135: }
136: 137: 138: 139: 140: 141:
142: function error404($params) {
143: extract($params, EXTR_OVERWRITE);
144:
145: if (!isset($url)) {
146: $url = $this->controller->here;
147: }
148: $url = Router::normalize($url);
149: header("HTTP/1.0 404 Not Found");
150: $this->controller->set(array(
151: 'code' => '404',
152: 'name' => __('Not Found', true),
153: 'message' => h($url),
154: 'base' => $this->controller->base
155: ));
156: $this->_outputMessage('error404');
157: }
158: 159: 160: 161: 162: 163:
164: function missingController($params) {
165: extract($params, EXTR_OVERWRITE);
166:
167: $controllerName = str_replace('Controller', '', $className);
168: $this->controller->set(array(
169: 'controller' => $className,
170: 'controllerName' => $controllerName,
171: 'title' => __('Missing Controller', true)
172: ));
173: $this->_outputMessage('missingController');
174: }
175: 176: 177: 178: 179: 180:
181: function missingAction($params) {
182: extract($params, EXTR_OVERWRITE);
183:
184: $controllerName = str_replace('Controller', '', $className);
185: $this->controller->set(array(
186: 'controller' => $className,
187: 'controllerName' => $controllerName,
188: 'action' => $action,
189: 'title' => __('Missing Method in Controller', true)
190: ));
191: $this->_outputMessage('missingAction');
192: }
193: 194: 195: 196: 197: 198:
199: function privateAction($params) {
200: extract($params, EXTR_OVERWRITE);
201:
202: $this->controller->set(array(
203: 'controller' => $className,
204: 'action' => $action,
205: 'title' => __('Trying to access private method in class', true)
206: ));
207: $this->_outputMessage('privateAction');
208: }
209: 210: 211: 212: 213: 214:
215: function missingTable($params) {
216: extract($params, EXTR_OVERWRITE);
217:
218: $this->controller->set(array(
219: 'model' => $className,
220: 'table' => $table,
221: 'title' => __('Missing Database Table', true)
222: ));
223: $this->_outputMessage('missingTable');
224: }
225: 226: 227: 228: 229: 230:
231: function missingDatabase($params = array()) {
232: $this->controller->set(array(
233: 'title' => __('Scaffold Missing Database Connection', true)
234: ));
235: $this->_outputMessage('missingScaffolddb');
236: }
237: 238: 239: 240: 241: 242:
243: function missingView($params) {
244: extract($params, EXTR_OVERWRITE);
245:
246: $this->controller->set(array(
247: 'controller' => $className,
248: 'action' => $action,
249: 'file' => $file,
250: 'title' => __('Missing View', true)
251: ));
252: $this->_outputMessage('missingView');
253: }
254: 255: 256: 257: 258: 259:
260: function missingLayout($params) {
261: extract($params, EXTR_OVERWRITE);
262:
263: $this->controller->layout = 'default';
264: $this->controller->set(array(
265: 'file' => $file,
266: 'title' => __('Missing Layout', true)
267: ));
268: $this->_outputMessage('missingLayout');
269: }
270: 271: 272: 273: 274: 275:
276: function missingConnection($params) {
277: extract($params, EXTR_OVERWRITE);
278:
279: $this->controller->set(array(
280: 'model' => $className,
281: 'title' => __('Missing Database Connection', true)
282: ));
283: $this->_outputMessage('missingConnection');
284: }
285: 286: 287: 288: 289: 290:
291: function missingHelperFile($params) {
292: extract($params, EXTR_OVERWRITE);
293:
294: $this->controller->set(array(
295: 'helperClass' => Inflector::camelize($helper) . "Helper",
296: 'file' => $file,
297: 'title' => __('Missing Helper File', true)
298: ));
299: $this->_outputMessage('missingHelperFile');
300: }
301: 302: 303: 304: 305: 306:
307: function missingHelperClass($params) {
308: extract($params, EXTR_OVERWRITE);
309:
310: $this->controller->set(array(
311: 'helperClass' => Inflector::camelize($helper) . "Helper",
312: 'file' => $file,
313: 'title' => __('Missing Helper Class', true)
314: ));
315: $this->_outputMessage('missingHelperClass');
316: }
317: 318: 319: 320: 321: 322:
323: function missingComponentFile($params) {
324: extract($params, EXTR_OVERWRITE);
325:
326: $this->controller->set(array(
327: 'controller' => $className,
328: 'component' => $component,
329: 'file' => $file,
330: 'title' => __('Missing Component File', true)
331: ));
332: $this->_outputMessage('missingComponentFile');
333: }
334: 335: 336: 337: 338: 339:
340: function missingComponentClass($params) {
341: extract($params, EXTR_OVERWRITE);
342:
343: $this->controller->set(array(
344: 'controller' => $className,
345: 'component' => $component,
346: 'file' => $file,
347: 'title' => __('Missing Component Class', true)
348: ));
349: $this->_outputMessage('missingComponentClass');
350: }
351: 352: 353: 354: 355: 356:
357: function missingModel($params) {
358: extract($params, EXTR_OVERWRITE);
359:
360: $this->controller->set(array(
361: 'model' => $className,
362: 'title' => __('Missing Model', true)
363: ));
364: $this->_outputMessage('missingModel');
365: }
366: 367: 368: 369: 370:
371: function _outputMessage($template) {
372: $this->controller->render($template);
373: $this->controller->afterFilter();
374: echo $this->controller->output;
375: }
376: }
377: ?>