error.php

Go to the documentation of this file.
00001 <?php
00002 /* SVN FILE: $Id: console_2error_8php-source.html 580 2008-07-01 14:45:49Z gwoo $ */
00003 /**
00004  * ErrorHandler for Console Shells
00005  *
00006  * Long description for file
00007  *
00008  * PHP versions 4 and 5
00009  *
00010  * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
00011  * Copyright 2005-2008, Cake Software Foundation, Inc.
00012  *                              1785 E. Sahara Avenue, Suite 490-204
00013  *                              Las Vegas, Nevada 89104
00014  *
00015  * Licensed under The MIT License
00016  * Redistributions of files must retain the above copyright notice.
00017  *
00018  * @filesource
00019  * @copyright       Copyright 2005-2008, Cake Software Foundation, Inc.
00020  * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
00021  * @package         cake
00022  * @subpackage      cake.cake.console
00023  * @since           CakePHP(tm) v 1.2.0.5074
00024  * @version         $Revision: 580 $
00025  * @modifiedby      $LastChangedBy: gwoo $
00026  * @lastmodified    $Date: 2008-07-01 09:45:49 -0500 (Tue, 01 Jul 2008) $
00027  * @license         http://www.opensource.org/licenses/mit-license.php The MIT License
00028  */
00029 /**
00030  * Error Handler for Cake console.
00031  *
00032  * @package     cake
00033  * @subpackage  cake.cake.console
00034  */
00035 class ErrorHandler extends Object {
00036 /**
00037  * Standard output stream.
00038  *
00039  * @var filehandle
00040  * @access public
00041  */
00042     var $stdout;
00043 /**
00044  * Standard error stream.
00045  *
00046  * @var filehandle
00047  * @access public
00048  */
00049     var $stderr;
00050 /**
00051  * Class constructor.
00052  *
00053  * @param string $method Method dispatching an error
00054  * @param array $messages Error messages
00055  */
00056     function __construct($method, $messages) {
00057         $this->stdout = fopen('php://stdout', 'w');
00058         $this->stderr = fopen('php://stderr', 'w');
00059         if (Configure::read() > 0 || $method == 'error') {
00060             call_user_func_array(array(&$this, $method), $messages);
00061         } else {
00062             call_user_func_array(array(&$this, 'error404'), $messages);
00063         }
00064     }
00065 /**
00066  * Displays an error page (e.g. 404 Not found).
00067  *
00068  * @param array $params Parameters (code, name, and message)
00069  * @access public
00070  */
00071     function error($params) {
00072         extract($params, EXTR_OVERWRITE);
00073         $this->stderr($code . $name . $message."\n");
00074         $this->_stop();
00075     }
00076 /**
00077  * Convenience method to display a 404 page.
00078  *
00079  * @param array $params Parameters (url, message)
00080  * @access public
00081  */
00082     function error404($params) {
00083         extract($params, EXTR_OVERWRITE);
00084         $this->error(array('code' => '404',
00085                             'name' => 'Not found',
00086                             'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message)));
00087         $this->_stop();
00088     }
00089 /**
00090  * Renders the Missing Controller web page.
00091  *
00092  * @param array $params Parameters (className)
00093  * @access public
00094  */
00095     function missingController($params) {
00096         extract($params, EXTR_OVERWRITE);
00097         $controllerName = str_replace('Controller', '', $className);
00098         $this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName));
00099         $this->_stop();
00100     }
00101 /**
00102  * Renders the Missing Action web page.
00103  *
00104  * @param array $params Parameters (action, className)
00105  * @access public
00106  */
00107     function missingAction($params) {
00108         extract($params, EXTR_OVERWRITE);
00109         $this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className));
00110         $this->_stop();
00111     }
00112 /**
00113  * Renders the Private Action web page.
00114  *
00115  * @param array $params Parameters (action, className)
00116  * @access public
00117  */
00118     function privateAction($params) {
00119         extract($params, EXTR_OVERWRITE);
00120         $this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className));
00121         $this->_stop();
00122     }
00123 /**
00124  * Renders the Missing Table web page.
00125  *
00126  * @param array $params Parameters (table, className)
00127  * @access public
00128  */
00129     function missingTable($params) {
00130         extract($params, EXTR_OVERWRITE);
00131         $this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className));
00132         $this->_stop();
00133     }
00134 /**
00135  * Renders the Missing Database web page.
00136  *
00137  * @param array $params Parameters
00138  * @access public
00139  */
00140     function missingDatabase($params = array()) {
00141         extract($params, EXTR_OVERWRITE);
00142         $this->stderr(__("Missing Database", true));
00143         $this->_stop();
00144     }
00145 /**
00146  * Renders the Missing View web page.
00147  *
00148  * @param array $params Parameters (file, action, className)
00149  * @access public
00150  */
00151     function missingView($params) {
00152         extract($params, EXTR_OVERWRITE);
00153         $this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className));
00154         $this->_stop();
00155     }
00156 /**
00157  * Renders the Missing Layout web page.
00158  *
00159  * @param array $params Parameters (file)
00160  * @access public
00161  */
00162     function missingLayout($params) {
00163         extract($params, EXTR_OVERWRITE);
00164         $this->stderr(sprintf(__("Missing Layout '%s'", true), $file));
00165         $this->_stop();
00166     }
00167 /**
00168  * Renders the Database Connection web page.
00169  *
00170  * @param array $params Parameters
00171  * @access public
00172  */
00173     function missingConnection($params) {
00174         extract($params, EXTR_OVERWRITE);
00175         $this->stderr(__("Missing Database Connection. Try 'cake bake'", true));
00176         $this->_stop();
00177     }
00178 /**
00179  * Renders the Missing Helper file web page.
00180  *
00181  * @param array $params Parameters (file, helper)
00182  * @access public
00183  */
00184     function missingHelperFile($params) {
00185         extract($params, EXTR_OVERWRITE);
00186         $this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector::camelize($helper)));
00187         $this->_stop();
00188     }
00189 /**
00190  * Renders the Missing Helper class web page.
00191  *
00192  * @param array $params Parameters (file, helper)
00193  * @access public
00194  */
00195     function missingHelperClass($params) {
00196         extract($params, EXTR_OVERWRITE);
00197         $this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector::camelize($helper), $file));
00198         $this->_stop();
00199     }
00200 /**
00201  * Renders the Missing Component file web page.
00202  *
00203  * @param array $params Parameters (file, component)
00204  * @access public
00205  */
00206     function missingComponentFile($params) {
00207         extract($params, EXTR_OVERWRITE);
00208         $this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector::camelize($component)));
00209         $this->_stop();
00210     }
00211 /**
00212  * Renders the Missing Component class web page.
00213  *
00214  * @param array $params Parameters (file, component)
00215  * @access public
00216  */
00217     function missingComponentClass($params) {
00218         extract($params, EXTR_OVERWRITE);
00219         $this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector::camelize($component), $file));
00220         $this->_stop();
00221     }
00222 /**
00223  * Renders the Missing Model class web page.
00224  *
00225  * @param array $params Parameters (className)
00226  * @access public
00227  */
00228     function missingModel($params) {
00229         extract($params, EXTR_OVERWRITE);
00230         $this->stderr(sprintf(__("Missing model '%s'", true), $className));
00231         $this->_stop();
00232     }
00233 /**
00234  * Outputs to the stdout filehandle.
00235  *
00236  * @param string $string String to output.
00237  * @param boolean $newline If true, the outputs gets an added newline.
00238  * @access public
00239  */
00240     function stdout($string, $newline = true) {
00241         if ($newline) {
00242             fwrite($this->stdout, $string . "\n");
00243         } else {
00244             fwrite($this->stdout, $string);
00245         }
00246     }
00247 /**
00248  * Outputs to the stderr filehandle.
00249  *
00250  * @param string $string Error text to output.
00251  * @access public
00252  */
00253     function stderr($string) {
00254         fwrite($this->stderr, "Error: ". $string . "\n");
00255     }
00256 }
00257 ?>