Subversion-Projekte lars-tiefland.cakephp

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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