2008-06-06 06:37:07 +02:00
|
|
|
<?php
|
2008-08-11 00:52:52 +02:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage dev
|
|
|
|
*/
|
|
|
|
|
2008-06-06 06:37:07 +02:00
|
|
|
/**
|
|
|
|
* A basic HTML wrapper for stylish rendering of a developement info view.
|
|
|
|
* Used to output error messages, and test results.
|
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage dev
|
|
|
|
*/
|
2010-10-15 05:43:30 +02:00
|
|
|
class DebugView extends Object {
|
2008-06-06 06:37:07 +02:00
|
|
|
|
2008-08-13 10:40:02 +02:00
|
|
|
protected static $error_types = array(
|
|
|
|
E_USER_ERROR => array(
|
|
|
|
'title' => 'User Error',
|
|
|
|
'class' => 'error'
|
|
|
|
),
|
|
|
|
E_CORE_ERROR => array(
|
|
|
|
'title' => 'Core Error',
|
|
|
|
'class' => 'error'
|
|
|
|
),
|
|
|
|
E_NOTICE => array(
|
|
|
|
'title' => 'Notice',
|
|
|
|
'class' => 'notice'
|
|
|
|
),
|
2009-08-19 08:03:57 +02:00
|
|
|
E_USER_NOTICE => array(
|
2009-08-19 08:20:25 +02:00
|
|
|
'title' => 'User Notice',
|
2009-08-19 08:03:57 +02:00
|
|
|
'class' => 'notice'
|
|
|
|
),
|
2012-03-27 11:54:13 +02:00
|
|
|
E_DEPRECATED => array(
|
2012-04-03 00:28:07 +02:00
|
|
|
'title' => 'Deprecated',
|
2012-03-27 11:54:13 +02:00
|
|
|
'class' => 'notice'
|
|
|
|
),
|
2012-03-24 04:34:10 +01:00
|
|
|
E_USER_DEPRECATED => array(
|
2012-04-03 00:28:07 +02:00
|
|
|
'title' => 'User Deprecated',
|
2012-03-24 04:34:10 +01:00
|
|
|
'class' => 'notice'
|
|
|
|
),
|
2008-08-13 10:40:02 +02:00
|
|
|
E_CORE_ERROR => array(
|
|
|
|
'title' => 'Core Error',
|
|
|
|
'class' => 'error'
|
|
|
|
),
|
|
|
|
E_WARNING => array(
|
|
|
|
'title' => 'Warning',
|
|
|
|
'class' => 'warning'
|
|
|
|
),
|
|
|
|
E_CORE_WARNING => array(
|
|
|
|
'title' => 'Core Warning',
|
|
|
|
'class' => 'warning'
|
|
|
|
),
|
|
|
|
E_USER_WARNING => array(
|
2009-08-19 08:20:25 +02:00
|
|
|
'title' => 'User Warning',
|
2008-08-13 10:40:02 +02:00
|
|
|
'class' => 'warning'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2008-08-11 01:03:35 +02:00
|
|
|
/**
|
|
|
|
* Generate breadcrumb links to the URL path being displayed
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function Breadcrumbs() {
|
|
|
|
$basePath = str_replace(Director::protocolAndHost(), '', Director::absoluteBaseURL());
|
2008-11-10 03:35:14 +01:00
|
|
|
$relPath = parse_url(substr($_SERVER['REQUEST_URI'], strlen($basePath), strlen($_SERVER['REQUEST_URI'])), PHP_URL_PATH);
|
2008-10-10 15:05:37 +02:00
|
|
|
$parts = explode('/', $relPath);
|
2008-08-11 01:03:35 +02:00
|
|
|
$base = Director::absoluteBaseURL();
|
|
|
|
$pathPart = "";
|
2008-10-10 15:05:37 +02:00
|
|
|
$pathLinks = array();
|
2008-08-11 01:03:35 +02:00
|
|
|
foreach($parts as $part) {
|
|
|
|
if ($part != '') {
|
|
|
|
$pathPart .= "$part/";
|
2008-10-10 15:05:37 +02:00
|
|
|
$pathLinks[] = "<a href=\"$base$pathPart\">$part</a>";
|
2008-08-11 01:03:35 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-10 15:05:37 +02:00
|
|
|
return implode('→ ', $pathLinks);
|
2008-08-11 01:03:35 +02:00
|
|
|
}
|
|
|
|
|
2008-06-06 06:37:07 +02:00
|
|
|
/**
|
|
|
|
* Render HTML header for development views
|
|
|
|
*/
|
|
|
|
public function writeHeader() {
|
2010-12-08 00:53:42 +01:00
|
|
|
$url = htmlentities(
|
|
|
|
$_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'],
|
|
|
|
ENT_COMPAT,
|
|
|
|
'UTF-8'
|
|
|
|
);
|
|
|
|
echo '<!DOCTYPE html><html><head><title>' . $url . '</title>';
|
2008-06-06 06:37:07 +02:00
|
|
|
echo '<style type="text/css">';
|
|
|
|
echo 'body { background-color:#eee; margin:0; padding:0; font-family:Helvetica,Arial,sans-serif; }';
|
2012-04-05 02:01:27 +02:00
|
|
|
echo '.info { margin:15px 0 0 0; padding:6px 12px; }';
|
2008-06-06 06:37:07 +02:00
|
|
|
echo '.info h1 { margin:0; padding:0; color:#333; letter-spacing:-2px; }';
|
|
|
|
echo '.header { margin:0; border-bottom:6px solid #ccdef3; height:23px; background-color:#666673; padding:4px 0 2px 6px; background-image:url('.Director::absoluteBaseURL().'cms/images/mainmenu/top-bg.gif); }';
|
|
|
|
echo '.trace { padding:6px 12px; }';
|
|
|
|
echo '.trace li { font-size:14px; margin:6px 0; }';
|
|
|
|
echo 'pre { margin-left:18px; }';
|
|
|
|
echo 'pre span { color:#999;}';
|
|
|
|
echo 'pre .error { color:#f00; }';
|
2012-04-05 02:01:27 +02:00
|
|
|
echo '.pass { margin-top:18px; padding:2px 20px 2px 40px; color:#006600; background:#E2F9E3 url('.Director::absoluteBaseURL() .'cms/images/alert-good.gif) no-repeat scroll 7px 50%; border:1px solid #8DD38D; border-radius:4px; }';
|
|
|
|
echo '.fail { margin-top:18px; padding:2px 20px 2px 40px; color:#C80700; background:#FFE9E9 url('.Director::absoluteBaseURL() .'cms/images/alert-bad.gif) no-repeat scroll 7px 50%; border:1px solid #C80700; border-radius:4px; }';
|
2008-06-06 06:37:07 +02:00
|
|
|
echo '.failure span { color:#C80700; font-weight:bold; }';
|
|
|
|
echo '</style></head>';
|
|
|
|
echo '<body>';
|
|
|
|
}
|
|
|
|
|
2008-08-11 01:03:35 +02:00
|
|
|
/**
|
|
|
|
* Render the information header for the view
|
|
|
|
*
|
|
|
|
* @param string $title
|
|
|
|
* @param string $title
|
|
|
|
*/
|
|
|
|
public function writeInfo($title, $subtitle, $description=false) {
|
|
|
|
echo '<div class="info">';
|
2008-11-05 06:04:32 +01:00
|
|
|
echo "<h1>" . Convert::raw2xml($title) . "</h1>";
|
2008-11-09 16:34:29 +01:00
|
|
|
if($subtitle) echo "<h3>" . Convert::raw2xml($subtitle) . "</h3>";
|
2008-08-11 01:03:35 +02:00
|
|
|
if ($description) {
|
|
|
|
echo "<p>$description</p>";
|
|
|
|
} else {
|
|
|
|
echo $this->Breadcrumbs();
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
|
2008-06-06 06:37:07 +02:00
|
|
|
/**
|
|
|
|
* Render HTML footer for development views
|
|
|
|
*/
|
|
|
|
public function writeFooter() {
|
|
|
|
echo "</body></html>";
|
|
|
|
}
|
2008-08-11 06:02:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write information about the error to the screen
|
|
|
|
*/
|
|
|
|
public function writeError($httpRequest, $errno, $errstr, $errfile, $errline, $errcontext) {
|
2008-08-13 10:40:02 +02:00
|
|
|
$errorType = self::$error_types[$errno];
|
2011-11-29 10:43:06 +01:00
|
|
|
$httpRequestEnt = htmlentities($httpRequest, ENT_COMPAT, 'UTF-8');
|
2008-08-13 10:40:02 +02:00
|
|
|
echo '<div class="info ' . $errorType['class'] . '">';
|
|
|
|
echo "<h1>[" . $errorType['title'] . '] ' . strip_tags($errstr) . "</h1>";
|
2009-08-25 05:11:22 +02:00
|
|
|
echo "<h3>$httpRequestEnt</h3>";
|
2008-08-11 06:02:32 +02:00
|
|
|
echo "<p>Line <strong>$errline</strong> in <strong>$errfile</strong></p>";
|
|
|
|
echo '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a fragment of the a source file
|
|
|
|
* @param $lines An array of file lines; the keys should be the original line numbers
|
|
|
|
*/
|
|
|
|
function writeSourceFragment($lines, $errline) {
|
|
|
|
echo '<div class="trace"><h3>Source</h3>';
|
|
|
|
echo '<pre>';
|
|
|
|
foreach($lines as $offset => $line) {
|
2010-12-08 00:53:42 +01:00
|
|
|
$line = htmlentities($line, ENT_COMPAT, 'UTF-8');
|
2008-08-11 06:02:32 +02:00
|
|
|
if ($offset == $errline) {
|
|
|
|
echo "<span>$offset</span> <span class=\"error\">$line</span>";
|
|
|
|
} else {
|
|
|
|
echo "<span>$offset</span> $line";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</pre>';
|
|
|
|
}
|
2008-06-06 06:37:07 +02:00
|
|
|
|
2008-08-11 06:02:32 +02:00
|
|
|
/**
|
|
|
|
* Write a backtrace
|
|
|
|
*/
|
2009-01-20 22:30:12 +01:00
|
|
|
function writeTrace($trace) {
|
2008-08-11 06:02:32 +02:00
|
|
|
echo '<h3>Trace</h3>';
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
echo SS_Backtrace::get_rendered_backtrace($trace);
|
2008-08-11 06:02:32 +02:00
|
|
|
echo '</div>';
|
|
|
|
}
|
2008-10-01 16:43:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $text
|
|
|
|
*/
|
|
|
|
function writeParagraph($text) {
|
|
|
|
echo '<p class="info">' . $text . '</p>';
|
|
|
|
}
|
2008-06-06 06:37:07 +02:00
|
|
|
}
|
|
|
|
|