ENHANCEMENT Added Debug::send_warnings_to()

API CHANGE Deprecated Debug::mailBuffer()
API CHANGE Removed Debug::warning()
MINOR Documentation and formatting for Debug class

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@62843 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-09-22 16:03:19 +00:00
parent 3776311276
commit 306ea3761f

View File

@ -1,10 +1,4 @@
<?php <?php
/**
* @package sapphire
* @subpackage core
*/
/** /**
* Supports debugging and core error handling. * Supports debugging and core error handling.
* *
@ -90,7 +84,9 @@ class Debug {
} }
/** /**
* Emails the contents of the output buffer * Emails the contents of the output buffer.
*
* @deprecated Use custom code instead.
*/ */
static function mailBuffer( $email, $subject ) { static function mailBuffer( $email, $subject ) {
mail( $email, $subject, ob_get_contents() ); mail( $email, $subject, ob_get_contents() );
@ -193,16 +189,6 @@ class Debug {
file_put_contents($file, $content); file_put_contents($file, $content);
} }
private static $warning_pos = 220;
static function warning($notice) {
echo '<div style="background-color:#ccc;border:3px solid #999;position:absolute;right:0;bottom:'.self::$warning_pos.'px;">';
echo '<h6>Warning:</h6>';
echo '<p>'.$notice.'</p>';
echo '</div>';
self::$warning_pos = self::$warning_pos-50;
}
/** /**
* Load error handlers into environment. * Load error handlers into environment.
* Caution: The error levels default to E_ALL is the site is in dev-mode (set in main.php). * Caution: The error levels default to E_ALL is the site is in dev-mode (set in main.php).
@ -362,14 +348,16 @@ class Debug {
/** /**
* Dispatch an email notification message when an error is triggered. * Dispatch an email notification message when an error is triggered.
* Uses the native PHP mail() function.
* *
* @param unknown_type $emailAddress * @param string $emailAddress
* @param unknown_type $errno * @param string $errno
* @param unknown_type $errstr * @param string $errstr
* @param unknown_type $errfile * @param string $errfile
* @param unknown_type $errline * @param int $errline
* @param unknown_type $errcontext * @param string $errcontext
* @param unknown_type $errorType * @param string $errorType "warning" or "error"
* @return boolean
*/ */
static function emailError($emailAddress, $errno, $errstr, $errfile, $errline, $errcontext, $errorType = "Error") { static function emailError($emailAddress, $errno, $errstr, $errfile, $errline, $errcontext, $errorType = "Error") {
if(strtolower($errorType) == 'warning') { if(strtolower($errorType) == 'warning') {
@ -385,17 +373,22 @@ class Debug {
$data .= "</div>\n"; $data .= "</div>\n";
// override smtp-server if needed // override smtp-server if needed
if(self::$custom_smtp_server) { if(self::$custom_smtp_server) ini_set("SMTP", self::$custom_smtp_server);
ini_set("SMTP", self::$custom_smtp_server);
}
$relfile = Director::makeRelative($errfile); $relfile = Director::makeRelative($errfile);
if($relfile[0] == '/') $relfile = substr($relfile,1); if($relfile[0] == '/') $relfile = substr($relfile,1);
mail($emailAddress, "$errorType at $relfile line $errline (http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI])", $data, "Content-type: text/html\nFrom: errors@silverstripe.com");
return mail($emailAddress, "$errorType at $relfile line $errline (http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI])", $data, "Content-type: text/html\nFrom: errors@silverstripe.com");
} }
/** /**
* Log the given error, if self::$log_errors is set. * Log the given error, if self::$log_errors is set.
* Uses the native error_log() funtion in PHP.
*
* Format: [d-M-Y h:i:s] <type> at <file> line <line>: <errormessage> <url>
*
* @todo Detect script path for CLI errors
* @todo Log detailed errors to full file
*/ */
protected static function log_error_if_necessary($errno, $errstr, $errfile, $errline, $errcontext, $errtype) { protected static function log_error_if_necessary($errno, $errstr, $errfile, $errline, $errcontext, $errtype) {
if(self::$log_errors_to) { if(self::$log_errors_to) {
@ -432,8 +425,9 @@ class Debug {
* Send errors to the given email address. * Send errors to the given email address.
* Can be used like so: * Can be used like so:
* if(Director::isLive()) Debug::send_errors_to("sam@silverstripe.com"); * if(Director::isLive()) Debug::send_errors_to("sam@silverstripe.com");
* @param emailAddress The email address to send them to *
* @param sendWarnings Set to true to send warnings as well as errors. * @param string $emailAddress The email address to send errors to
* @param string $sendWarnings Set to true to send warnings as well as errors (Default: true)
*/ */
static function send_errors_to($emailAddress, $sendWarnings = true) { static function send_errors_to($emailAddress, $sendWarnings = true) {
self::$send_errors_to = $emailAddress; self::$send_errors_to = $emailAddress;
@ -447,6 +441,13 @@ class Debug {
return self::$send_errors_to; return self::$send_errors_to;
} }
/**
* @param string $emailAddress
*/
static function send_warnings_to($emailAddress) {
self::$send_warnings_to = $emailAddress;
}
/** /**
* @return string * @return string
*/ */
@ -602,11 +603,21 @@ class Debug {
die(); die();
} }
} }
/** /**
* Generic callback, to catch uncaught exceptions when they bubble up to the top of the call chain. * Generic callback, to catch uncaught exceptions when they bubble up to the top of the call chain.
* *
* @ignore * @ignore
* @param unknown_type $exception * @param Exception $exception
*/ */
function exceptionHandler($exception) { function exceptionHandler($exception) {
$errno = E_USER_ERROR; $errno = E_USER_ERROR;
@ -624,11 +635,11 @@ function exceptionHandler($exception) {
* Caution: The error levels default to E_ALL is the site is in dev-mode (set in main.php). * Caution: The error levels default to E_ALL is the site is in dev-mode (set in main.php).
* *
* @ignore * @ignore
* @param unknown_type $errno * @param int $errno
* @param unknown_type $errstr * @param string $errstr
* @param unknown_type $errfile * @param string $errfile
* @param unknown_type $errline * @param int $errline
* @param unknown_type $errcontext * @param string $errcontext
*/ */
function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
switch($errno) { switch($errno) {