2008-08-11 06:02:32 +02:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\Dev;
|
|
|
|
|
2016-09-09 08:43:05 +02:00
|
|
|
use SilverStripe\Control\HTTPRequest;
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2008-08-11 06:02:32 +02:00
|
|
|
/**
|
|
|
|
* A basic HTML wrapper for stylish rendering of a developement info view.
|
|
|
|
* Used to output error messages, and test results.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-08-11 06:02:32 +02:00
|
|
|
* @todo Perhaps DebugView should be an interface / ABC, implemented by HTMLDebugView and CliDebugView?
|
|
|
|
*/
|
2015-07-27 02:19:55 +02:00
|
|
|
class CliDebugView extends DebugView
|
|
|
|
{
|
2008-08-11 06:02:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render HTML header for development views
|
2016-08-19 00:51:35 +02:00
|
|
|
*
|
2016-09-09 08:43:05 +02:00
|
|
|
* @param HTTPRequest $httpRequest
|
2016-08-19 00:51:35 +02:00
|
|
|
* @return string
|
2008-08-11 06:02:32 +02:00
|
|
|
*/
|
2015-07-27 02:19:55 +02:00
|
|
|
public function renderHeader($httpRequest = null) {
|
2016-08-19 00:51:35 +02:00
|
|
|
return null;
|
2008-08-11 06:02:32 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-08-11 06:02:32 +02:00
|
|
|
/**
|
|
|
|
* Render HTML footer for development views
|
|
|
|
*/
|
2015-07-27 02:19:55 +02:00
|
|
|
public function renderFooter() {
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|
2008-08-11 06:02:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write information about the error to the screen
|
2016-08-19 00:51:35 +02:00
|
|
|
*
|
|
|
|
* @param string $httpRequest
|
|
|
|
* @param int $errno
|
|
|
|
* @param string $errstr
|
|
|
|
* @param string $errfile
|
|
|
|
* @param int $errline
|
|
|
|
* @return string
|
2008-08-11 06:02:32 +02:00
|
|
|
*/
|
2015-07-27 02:19:55 +02:00
|
|
|
public function renderError($httpRequest, $errno, $errstr, $errfile, $errline) {
|
|
|
|
if(!isset(self::$error_types[$errno])) {
|
|
|
|
$errorTypeTitle = "UNKNOWN TYPE, ERRNO $errno";
|
|
|
|
} else {
|
|
|
|
$errorTypeTitle = self::$error_types[$errno]['title'];
|
|
|
|
}
|
2016-09-09 08:43:05 +02:00
|
|
|
$output = CLI::text("ERROR [" . $errorTypeTitle . "]: $errstr\nIN $httpRequest\n", "red", null, true);
|
|
|
|
$output .= CLI::text("Line $errline in $errfile\n\n", "red");
|
2015-07-27 02:19:55 +02:00
|
|
|
|
|
|
|
return $output;
|
2008-08-11 06:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a fragment of the a source file
|
2016-08-19 00:51:35 +02:00
|
|
|
*
|
|
|
|
* @param array $lines An array of file lines; the keys should be the original line numbers
|
|
|
|
* @param int $errline Index of the line in $lines which has the error
|
|
|
|
* @return string
|
2008-08-11 06:02:32 +02:00
|
|
|
*/
|
2015-07-27 02:19:55 +02:00
|
|
|
public function renderSourceFragment($lines, $errline) {
|
|
|
|
$output = "Source\n======\n";
|
2008-08-11 06:02:32 +02:00
|
|
|
foreach($lines as $offset => $line) {
|
2015-07-27 02:19:55 +02:00
|
|
|
$output .= ($offset == $errline) ? "* " : " ";
|
|
|
|
$output .= str_pad("$offset:", 5);
|
|
|
|
$output .= wordwrap($line, self::config()->columns, "\n ");
|
2008-08-11 06:02:32 +02:00
|
|
|
}
|
2015-07-27 02:19:55 +02:00
|
|
|
$output .= "\n";
|
|
|
|
|
|
|
|
return $output;
|
2008-08-11 06:02:32 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-08-11 06:02:32 +02:00
|
|
|
/**
|
|
|
|
* Write a backtrace
|
2016-08-19 00:51:35 +02:00
|
|
|
*
|
|
|
|
* @param array $trace
|
|
|
|
* @return string
|
2008-08-11 06:02:32 +02:00
|
|
|
*/
|
2015-07-27 02:19:55 +02:00
|
|
|
public function renderTrace($trace = null) {
|
|
|
|
$output = "Trace\n=====\n";
|
2016-09-09 08:43:05 +02:00
|
|
|
$output .= Backtrace::get_rendered_backtrace($trace ? $trace : debug_backtrace(), true);
|
2015-07-27 02:19:55 +02:00
|
|
|
|
|
|
|
return $output;
|
2008-08-11 06:02:32 +02:00
|
|
|
}
|
2008-08-13 03:47:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the information header for the view
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-08-13 03:47:05 +02:00
|
|
|
* @param string $title
|
2016-08-19 00:51:35 +02:00
|
|
|
* @param string $subtitle
|
|
|
|
* @param string $description
|
|
|
|
* @return string
|
2008-08-13 03:47:05 +02:00
|
|
|
*/
|
2016-08-19 00:51:35 +02:00
|
|
|
public function renderInfo($title, $subtitle, $description = null) {
|
2015-07-27 02:19:55 +02:00
|
|
|
$output = wordwrap(strtoupper($title), self::config()->columns) . "\n";
|
|
|
|
$output .= wordwrap($subtitle, self::config()->columns) . "\n";
|
|
|
|
$output .= str_repeat('-', min(self::config()->columns, max(strlen($title), strlen($subtitle)))) . "\n";
|
|
|
|
$output .= wordwrap($description, self::config()->columns) . "\n\n";
|
|
|
|
|
|
|
|
return $output;
|
2008-08-13 03:47:05 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2015-07-27 02:19:55 +02:00
|
|
|
public function renderVariable($val, $caller) {
|
|
|
|
$output = PHP_EOL;
|
2016-09-09 08:43:05 +02:00
|
|
|
$output .= CLI::text(str_repeat('=', self::config()->columns), 'green');
|
2015-07-27 02:19:55 +02:00
|
|
|
$output .= PHP_EOL;
|
2016-09-09 08:43:05 +02:00
|
|
|
$output .= CLI::text($this->formatCaller($caller), 'blue', null, true);
|
2015-07-27 02:19:55 +02:00
|
|
|
$output .= PHP_EOL.PHP_EOL;
|
2014-07-05 04:37:06 +02:00
|
|
|
if (is_string($val)) {
|
2015-07-27 02:19:55 +02:00
|
|
|
$output .= wordwrap($val, self::config()->columns);
|
2014-07-05 04:37:06 +02:00
|
|
|
} else {
|
2015-07-27 02:19:55 +02:00
|
|
|
$output .= var_export($val, true);
|
2014-07-05 04:37:06 +02:00
|
|
|
}
|
2015-07-27 02:19:55 +02:00
|
|
|
$output .= PHP_EOL;
|
2016-09-09 08:43:05 +02:00
|
|
|
$output .= CLI::text(str_repeat('=', self::config()->columns), 'green');
|
2015-07-27 02:19:55 +02:00
|
|
|
$output .= PHP_EOL;
|
|
|
|
|
|
|
|
return $output;
|
2014-07-05 04:37:06 +02:00
|
|
|
}
|
2008-08-11 06:02:32 +02:00
|
|
|
}
|