error.php

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

Generated on Sun Nov 22 00:30:51 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7