2008-06-06 06:37:07 +02:00
|
|
|
<?php
|
2008-08-11 00:52:52 +02:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-08-11 00:52:52 +02:00
|
|
|
* @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.
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-06-06 06:37:07 +02:00
|
|
|
* @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'
|
2012-04-11 04:39:02 +02:00
|
|
|
),
|
|
|
|
E_STRICT => array(
|
|
|
|
'title' => 'Strict Notice',
|
|
|
|
'class' => 'notice'
|
2008-08-13 10:40:02 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
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());
|
2012-09-26 23:34:00 +02: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
|
|
|
}
|
|
|
|
}
|
2012-09-01 01:58:52 +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'
|
|
|
|
);
|
2012-06-29 06:52:29 +02:00
|
|
|
|
|
|
|
$debugCSS = Controller::join_links(
|
|
|
|
Director::absoluteBaseURL(),
|
|
|
|
FRAMEWORK_DIR,
|
|
|
|
'css/debug.css'
|
|
|
|
);
|
|
|
|
|
2010-12-08 00:53:42 +01:00
|
|
|
echo '<!DOCTYPE html><html><head><title>' . $url . '</title>';
|
2012-06-29 06:52:29 +02:00
|
|
|
echo '<link rel="stylesheet" type="text/css" href="'. $debugCSS .'" />';
|
|
|
|
echo '</head>';
|
2008-06-06 06:37:07 +02:00
|
|
|
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
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function writeSourceFragment($lines, $errline) {
|
2008-08-11 06:02:32 +02:00
|
|
|
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
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public 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
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function writeParagraph($text) {
|
2008-10-01 16:43:43 +02:00
|
|
|
echo '<p class="info">' . $text . '</p>';
|
|
|
|
}
|
2008-06-06 06:37:07 +02:00
|
|
|
}
|
|
|
|
|