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
 * ErrorHandler for Console Shells
5
 *
6
 * Long description for file
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.console
21
 * @since         CakePHP(tm) v 1.2.0.5074
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
/**
28
 * Error Handler for Cake console.
29
 *
30
 * @package       cake
31
 * @subpackage    cake.cake.console
32
 */
33
class ErrorHandler extends Object {
34
/**
35
 * Standard output stream.
36
 *
37
 * @var filehandle
38
 * @access public
39
 */
40
	var $stdout;
41
/**
42
 * Standard error stream.
43
 *
44
 * @var filehandle
45
 * @access public
46
 */
47
	var $stderr;
48
/**
49
 * Class constructor.
50
 *
51
 * @param string $method Method dispatching an error
52
 * @param array $messages Error messages
53
 */
54
	function __construct($method, $messages) {
55
		$this->stdout = fopen('php://stdout', 'w');
56
		$this->stderr = fopen('php://stderr', 'w');
57
		if (Configure::read() > 0 || $method == 'error') {
58
			call_user_func_array(array(&$this, $method), $messages);
59
		} else {
60
			call_user_func_array(array(&$this, 'error404'), $messages);
61
		}
62
	}
63
/**
64
 * Displays an error page (e.g. 404 Not found).
65
 *
66
 * @param array $params Parameters (code, name, and message)
67
 * @access public
68
 */
69
	function error($params) {
70
		extract($params, EXTR_OVERWRITE);
71
		$this->stderr($code . $name . $message."\n");
72
		$this->_stop();
73
	}
74
/**
75
 * Convenience method to display a 404 page.
76
 *
77
 * @param array $params Parameters (url, message)
78
 * @access public
79
 */
80
	function error404($params) {
81
		extract($params, EXTR_OVERWRITE);
82
		$this->error(array('code' => '404',
83
							'name' => 'Not found',
84
							'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message)));
85
		$this->_stop();
86
	}
87
/**
88
 * Renders the Missing Controller web page.
89
 *
90
 * @param array $params Parameters (className)
91
 * @access public
92
 */
93
	function missingController($params) {
94
		extract($params, EXTR_OVERWRITE);
95
		$controllerName = str_replace('Controller', '', $className);
96
		$this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName));
97
		$this->_stop();
98
	}
99
/**
100
 * Renders the Missing Action web page.
101
 *
102
 * @param array $params Parameters (action, className)
103
 * @access public
104
 */
105
	function missingAction($params) {
106
		extract($params, EXTR_OVERWRITE);
107
		$this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className));
108
		$this->_stop();
109
	}
110
/**
111
 * Renders the Private Action web page.
112
 *
113
 * @param array $params Parameters (action, className)
114
 * @access public
115
 */
116
	function privateAction($params) {
117
		extract($params, EXTR_OVERWRITE);
118
		$this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className));
119
		$this->_stop();
120
	}
121
/**
122
 * Renders the Missing Table web page.
123
 *
124
 * @param array $params Parameters (table, className)
125
 * @access public
126
 */
127
	function missingTable($params) {
128
		extract($params, EXTR_OVERWRITE);
129
		$this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className));
130
		$this->_stop();
131
	}
132
/**
133
 * Renders the Missing Database web page.
134
 *
135
 * @param array $params Parameters
136
 * @access public
137
 */
138
	function missingDatabase($params = array()) {
139
		$this->stderr(__("Missing Database", true));
140
		$this->_stop();
141
	}
142
/**
143
 * Renders the Missing View web page.
144
 *
145
 * @param array $params Parameters (file, action, className)
146
 * @access public
147
 */
148
	function missingView($params) {
149
		extract($params, EXTR_OVERWRITE);
150
		$this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className));
151
		$this->_stop();
152
	}
153
/**
154
 * Renders the Missing Layout web page.
155
 *
156
 * @param array $params Parameters (file)
157
 * @access public
158
 */
159
	function missingLayout($params) {
160
		extract($params, EXTR_OVERWRITE);
161
		$this->stderr(sprintf(__("Missing Layout '%s'", true), $file));
162
		$this->_stop();
163
	}
164
/**
165
 * Renders the Database Connection web page.
166
 *
167
 * @param array $params Parameters
168
 * @access public
169
 */
170
	function missingConnection($params) {
171
		extract($params, EXTR_OVERWRITE);
172
		$this->stderr(__("Missing Database Connection. Try 'cake bake'", true));
173
		$this->_stop();
174
	}
175
/**
176
 * Renders the Missing Helper file web page.
177
 *
178
 * @param array $params Parameters (file, helper)
179
 * @access public
180
 */
181
	function missingHelperFile($params) {
182
		extract($params, EXTR_OVERWRITE);
183
		$this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector::camelize($helper)));
184
		$this->_stop();
185
	}
186
/**
187
 * Renders the Missing Helper class web page.
188
 *
189
 * @param array $params Parameters (file, helper)
190
 * @access public
191
 */
192
	function missingHelperClass($params) {
193
		extract($params, EXTR_OVERWRITE);
194
		$this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector::camelize($helper), $file));
195
		$this->_stop();
196
	}
197
/**
198
 * Renders the Missing Component file web page.
199
 *
200
 * @param array $params Parameters (file, component)
201
 * @access public
202
 */
203
	function missingComponentFile($params) {
204
		extract($params, EXTR_OVERWRITE);
205
		$this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector::camelize($component)));
206
		$this->_stop();
207
	}
208
/**
209
 * Renders the Missing Component class web page.
210
 *
211
 * @param array $params Parameters (file, component)
212
 * @access public
213
 */
214
	function missingComponentClass($params) {
215
		extract($params, EXTR_OVERWRITE);
216
		$this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector::camelize($component), $file));
217
		$this->_stop();
218
	}
219
/**
220
 * Renders the Missing Model class web page.
221
 *
222
 * @param array $params Parameters (className)
223
 * @access public
224
 */
225
	function missingModel($params) {
226
		extract($params, EXTR_OVERWRITE);
227
		$this->stderr(sprintf(__("Missing model '%s'", true), $className));
228
		$this->_stop();
229
	}
230
/**
231
 * Outputs to the stdout filehandle.
232
 *
233
 * @param string $string String to output.
234
 * @param boolean $newline If true, the outputs gets an added newline.
235
 * @access public
236
 */
237
	function stdout($string, $newline = true) {
238
		if ($newline) {
239
			fwrite($this->stdout, $string . "\n");
240
		} else {
241
			fwrite($this->stdout, $string);
242
		}
243
	}
244
/**
245
 * Outputs to the stderr filehandle.
246
 *
247
 * @param string $string Error text to output.
248
 * @access public
249
 */
250
	function stderr($string) {
251
		fwrite($this->stderr, "Error: ". $string . "\n");
252
	}
253
}
254
?>