3 * ErrorHandler for Console Shells
7 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
10 * Licensed under The MIT License
11 * Redistributions of files must retain the above copyright notice.
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14 * @link http://cakephp.org CakePHP(tm) Project
16 * @subpackage cake.cake.console
17 * @since CakePHP(tm) v 1.2.0.5074
18 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
22 * Error Handler for Cake console.
25 * @subpackage cake.cake.console
27 class ErrorHandler
extends Object {
30 * Standard output stream.
38 * Standard error stream.
48 * @param string $method Method dispatching an error
49 * @param array $messages Error messages
51 function __construct($method, $messages) {
52 $this->stdout
= fopen('php://stdout', 'w');
53 $this->stderr
= fopen('php://stderr', 'w');
54 call_user_func_array(array(&$this, $method), $messages);
58 * Displays an error page (e.g. 404 Not found).
60 * @param array $params Parameters (code, name, and message)
63 function error($params) {
64 extract($params, EXTR_OVERWRITE
);
65 $this->stderr($code . $name . $message."\n");
70 * Convenience method to display a 404 page.
72 * @param array $params Parameters (url, message)
75 function error404($params) {
76 extract($params, EXTR_OVERWRITE
);
79 'name' => 'Not found',
80 'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message)
86 * Renders the Missing Controller web page.
88 * @param array $params Parameters (className)
91 function missingController($params) {
92 extract($params, EXTR_OVERWRITE
);
93 $controllerName = str_replace('Controller', '', $className);
94 $this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName));
99 * Renders the Missing Action web page.
101 * @param array $params Parameters (action, className)
104 function missingAction($params) {
105 extract($params, EXTR_OVERWRITE
);
106 $this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className));
111 * Renders the Private Action web page.
113 * @param array $params Parameters (action, className)
116 function privateAction($params) {
117 extract($params, EXTR_OVERWRITE
);
118 $this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className));
123 * Renders the Missing Table web page.
125 * @param array $params Parameters (table, className)
128 function missingTable($params) {
129 extract($params, EXTR_OVERWRITE
);
130 $this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className));
135 * Renders the Missing Database web page.
137 * @param array $params Parameters
140 function missingDatabase($params = array()) {
141 $this->stderr(__("Missing Database", true));
146 * Renders the Missing View web page.
148 * @param array $params Parameters (file, action, className)
151 function missingView($params) {
152 extract($params, EXTR_OVERWRITE
);
153 $this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className));
158 * Renders the Missing Layout web page.
160 * @param array $params Parameters (file)
163 function missingLayout($params) {
164 extract($params, EXTR_OVERWRITE
);
165 $this->stderr(sprintf(__("Missing Layout '%s'", true), $file));
170 * Renders the Database Connection web page.
172 * @param array $params Parameters
175 function missingConnection($params) {
176 extract($params, EXTR_OVERWRITE
);
177 $this->stderr(__("Missing Database Connection. Try 'cake bake'", true));
182 * Renders the Missing Helper file web page.
184 * @param array $params Parameters (file, helper)
187 function missingHelperFile($params) {
188 extract($params, EXTR_OVERWRITE
);
189 $this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector
::camelize($helper)));
194 * Renders the Missing Helper class web page.
196 * @param array $params Parameters (file, helper)
199 function missingHelperClass($params) {
200 extract($params, EXTR_OVERWRITE
);
201 $this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector
::camelize($helper), $file));
206 * Renders the Missing Component file web page.
208 * @param array $params Parameters (file, component)
211 function missingComponentFile($params) {
212 extract($params, EXTR_OVERWRITE
);
213 $this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector
::camelize($component)));
218 * Renders the Missing Component class web page.
220 * @param array $params Parameters (file, component)
223 function missingComponentClass($params) {
224 extract($params, EXTR_OVERWRITE
);
225 $this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector
::camelize($component), $file));
230 * Renders the Missing Model class web page.
232 * @param array $params Parameters (className)
235 function missingModel($params) {
236 extract($params, EXTR_OVERWRITE
);
237 $this->stderr(sprintf(__("Missing model '%s'", true), $className));
242 * Outputs to the stdout filehandle.
244 * @param string $string String to output.
245 * @param boolean $newline If true, the outputs gets an added newline.
248 function stdout($string, $newline = true) {
250 fwrite($this->stdout
, $string . "\n");
252 fwrite($this->stdout
, $string);
257 * Outputs to the stderr filehandle.
259 * @param string $string Error text to output.
262 function stderr($string) {
263 fwrite($this->stderr
, "Error: ". $string . "\n");