Version: current

     1 <?php
     2 /**
     3  * A basic HTML wrapper for stylish rendering of a developement info view.
     4  * Used to output error messages, and test results.
     5  *
     6  * @package sapphire
     7  * @subpackage dev
     8  *
     9  * @todo Perhaps DebugView should be an interface / ABC, implemented by HTMLDebugView and CliDebugView?
    10  */
    11
    12 class CliDebugView extends DebugView {
    13
    14     /**
    15      * Render HTML header for development views
    16      */
    17     public function writeHeader($httpRequest = null) {
    18     }
    19
    20     /**
    21      * Render HTML footer for development views
    22      */
    23     public function writeFooter() {
    24     }
    25
    26     /**
    27      * Write information about the error to the screen
    28      */
    29     public function writeError($httpRequest, $errno, $errstr, $errfile, $errline, $errcontext) {
    30         $errorType = self::$error_types[$errno];
    31         echo SS_Cli::text("ERROR [" . $errorType['title'] . "]: $errstr\nIN $httpRequest\n", "red", null, true);
    32         echo SS_Cli::text("Line $errline in $errfile\n\n", "red");
    33     }
    34
    35     /**
    36      * Write a fragment of the a source file
    37      * @param $lines An array of file lines; the keys should be the original line numbers
    38      */
    39     function writeSourceFragment($lines, $errline) {
    40         echo "Source\n======\n";
    41         foreach($lines as $offset => $line) {
    42             echo ($offset == $errline) ? "* " : "  ";
    43             echo str_pad("$offset:",5);
    44             echo wordwrap($line, 100, "\n       ");
    45         }
    46         echo "\n";
    47     }
    48
    49     /**
    50      * Write a backtrace
    51      */
    52     function writeTrace($trace = null) {
    53         echo "Trace\n=====\n";
    54         echo SS_Backtrace::get_rendered_backtrace($trace ? $trace : debug_backtrace(), true);
    55     }
    56
    57     /**
    58      * Render the information header for the view
    59      *
    60      * @param string $title
    61      * @param string $title
    62      */
    63     public function writeInfo($title, $subtitle, $description=false) {
    64         echo wordwrap(strtoupper($title),100) . "\n";
    65         echo wordwrap($subtitle,100) . "\n";
    66         echo str_repeat('-',min(100,max(strlen($title),strlen($subtitle)))) . "\n";
    67         echo wordwrap($description,100) . "\n\n";
    68     }
    69
    70 }
    71
    72 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -