Welcome Guest (Login)Index How To Upload
User: Password:
Create account Recover password

Previous Polls

Poll: Favorite Dead Year - Playdown
1969(119) (13%)
1972(156) (17%)
1973(158) (17%)
1974(133) (14%)
1977(214) (24%)
1980(21) (2%)
1989(54) (6%)
1990(36) (4%)
Previous Polls

CENSE * * Copyright (c) 2008 Larry Root * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * @category Lroot * @package Lroot_Zend * @author Larry Root * @copyright Copyright (c) 2008, Larry Root (http://www.lroot.com) * @license http://opensource.org/licenses/mit-license.php MIT License * @version 1.0 */ /** * Handles the the formatting and display of expections thrown within the Zend * Framework. It goes beyond the standard expection dump by providing more error * information and presenting interactive source code for the main exception and * all elements within the stack trace (optional). Its implemented as a static * class and requires only a single line of code within the error controller. * Modify the output template within the render method to customize the look and * feel. * * @example ErrorController.php Example error controller integration * @category Lroot * @package Lroot_Zend * @author Larry Root * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) * @license http://opensource.org/licenses/mit-license.php MIT license */ class Lroot_Zend_ExceptionFormatter { /** * Suppresses the standard viewRenderer and directly outputs the formatted * exception (HTML, CSS and JavaScript. * * @param ArrayObject $error The error handler array object for the currently controller. Generally accessed via $this->_getParam('error_handler') from within the controller. * @param Zend_Controller_Action_HelperBroker $viewHelper The main view helper for the current controller. Generally accessed via $this->_helper from within the controller. * @param boolean $extended A flag used to dertmine if the stack trace should be extended to contain interactive source code or not. Browser performance is degraded when this feature is enabled. Default is false. */ static function display ($error, $extended = false, $return = false) { $data = array(); $data['errorMessage'] = $error['exception']->getMessage(); $data['errorType'] = $error['type']; $data['errorCode'] = $error['exception']->getCode(); $data['errorFilePath'] = $error['exception']->getFile(); $data['errorLineNumber'] = $error['exception']->getLine(); $data['errorLineNumberFormatted'] = self::addPadding( $error['exception']->getLine() ); $data['errorCodeBlock'] = self::generateCodeBlock( $error['exception']->getLine(), $error['exception']->getFile() ); $data['traceStack'] = array(); foreach( $error['exception']->getTrace() as $trace) { if ($extended) { $trace['lineNumberFormatted'] = self::addPadding( $trace['line'] ); $trace['codeBlock'] = self::generateCodeBlock( $trace['line'], $trace['file'] ); } $data['traceStack'][] = $trace; } $ret = self::render($data, $extended); if (!$return) echo $ret; else return $ret; } /** * Handles the formatting of function arguments values for a given function * within a stack trace. * @access private * @param array $args An array of function arguments * @return string Formatted arguments ready for display in the output * template. */ private static function formatArgValues ($args) { $values = array(); foreach($args as $arg) { if (is_object($arg)) { $values[] = get_class($arg); } elseif (is_null($arg)) { $values[] = 'NULL'; } elseif (is_array($arg)) { $values[] = 'Array('.count($arg).')'; } elseif (is_string($arg)) { $values[] = "'$arg'"; } else { $values[] = (string) $arg; } } return implode(', ', $values); } /** * Padds line numbers within the the source code using   to ensure * 5 positions. * * @access private * @todo This is a hacky way to go about this. Perhaps Ill revist it at * some point. * @param integer $number * @return string Number with appropriate padding applied */ private static function addPadding ($number) { $formattedNumber = str_pad($number, 5, '_', STR_PAD_RIGHT); return str_replace('_', ' ', $formattedNumber ); } /** * Loads the given file and highlights it via highlight_file method. It * then inserts formatted line numbers within the resulting and highlights * the error line. * * @access private * @param integer $errorLine The line on which the error occured * @param string $filePath The full file path to the source code in which * the error occured * @return string The result of of the highlight_file function (source code * formatted with HTML) with line numbers spliced in and wrapped in a * containing div for formatting and to provide a javascript DOM hook. */ private static function generateCodeBlock ($errorLine, $filePath) { $lines = explode( '
', highlight_file($filePath, true) ); $errorID = ''; for($n = 0; $n < count($lines); $n++) { $lineNumber = $n+1; $paddedNumber = self::addPadding( $lineNumber ); $errorClass = ''; list($errorClass, $errorID) = ($lineNumber == $errorLine) ? array('errorLine', md5( $errorLine.$filePath ) ) : array('',$errorID); $lines[ $n ] = "$paddedNumber".$lines[ $n ]; } return "
".implode("
\n", $lines).'
'; } /** * Outputs formatted HTML directly to the browser. This method defines the * HTML (CSS & JavaScript) template used for output using heredoc. * * @access private * @param array $data A hash of formatted strings ready for display * @param boolean $extended A flag used to dertmine if the stack trace should be extended to contain interactive source code or not. */ private static function render($data, $extended) { $compiledTrace = ''; foreach($data['traceStack'] as $trace) { $compiledTrace .= '
  • '."\n"; if ($extended) { $compiledTrace .= '
    open'.$trace['file'].'
    '."\n"; } else { $compiledTrace .= '
    '.$trace['line'].''.$trace['file'].'
    '."\n"; } $compiledTrace .= '
    '.$trace['class'].'->'.$trace['function'].'('.self::formatArgValues($trace['args']).')
    '."\n"; if ($extended) { $compiledTrace .= $trace['codeBlock']."\n"; } $compiledTrace .= '
  • '."\n"; } if ($extended == false) $data['errorCodeBlock'] = ''; $ret = << Fatal Error: {$data["errorMessage"]}
    Fatal Error {$data['errorMessage']}
    {$data['errorType']} : {$data['errorCode']}
    open{$data['errorFilePath']}
    {$data['errorCodeBlock']}
    Stack trace
      $compiledTrace
    EOT; return $ret; } }
    Fatal error: Class 'Lroot_Zend_ExceptionFormatter' not found in /home/ben/public_html/bootstrap.php on line 47