diff --git a/dev/CliDebugView.php b/dev/CliDebugView.php index bec31e511..c7ee869d8 100644 --- a/dev/CliDebugView.php +++ b/dev/CliDebugView.php @@ -9,49 +9,60 @@ * @todo Perhaps DebugView should be an interface / ABC, implemented by HTMLDebugView and CliDebugView? */ -class CliDebugView extends DebugView { +class CliDebugView extends DebugView +{ /** * Render HTML header for development views */ - public function writeHeader($httpRequest = null) { + public function renderHeader($httpRequest = null) { } /** * Render HTML footer for development views */ - public function writeFooter() { + public function renderFooter() { } /** * Write information about the error to the screen */ - public function writeError($httpRequest, $errno, $errstr, $errfile, $errline, $errcontext) { - $errorType = self::$error_types[$errno]; - echo SS_Cli::text("ERROR [" . $errorType['title'] . "]: $errstr\nIN $httpRequest\n", "red", null, true); - echo SS_Cli::text("Line $errline in $errfile\n\n", "red"); + 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']; + } + $output = SS_Cli::text("ERROR [" . $errorTypeTitle . "]: $errstr\nIN $httpRequest\n", "red", null, true); + $output .= SS_Cli::text("Line $errline in $errfile\n\n", "red"); + + return $output; } /** * Write a fragment of the a source file * @param $lines An array of file lines; the keys should be the original line numbers */ - public function writeSourceFragment($lines, $errline) { - echo "Source\n======\n"; + public function renderSourceFragment($lines, $errline) { + $output = "Source\n======\n"; foreach($lines as $offset => $line) { - echo ($offset == $errline) ? "* " : " "; - echo str_pad("$offset:",5); - echo wordwrap($line, self::config()->columns, "\n "); + $output .= ($offset == $errline) ? "* " : " "; + $output .= str_pad("$offset:", 5); + $output .= wordwrap($line, self::config()->columns, "\n "); } - echo "\n"; + $output .= "\n"; + + return $output; } /** * Write a backtrace */ - public function writeTrace($trace = null) { - echo "Trace\n=====\n"; - echo SS_Backtrace::get_rendered_backtrace($trace ? $trace : debug_backtrace(), true); + public function renderTrace($trace = null) { + $output = "Trace\n=====\n"; + $output .= SS_Backtrace::get_rendered_backtrace($trace ? $trace : debug_backtrace(), true); + + return $output; } /** @@ -60,26 +71,30 @@ class CliDebugView extends DebugView { * @param string $title * @param string $title */ - public function writeInfo($title, $subtitle, $description=false) { - echo wordwrap(strtoupper($title),self::config()->columns) . "\n"; - echo wordwrap($subtitle,self::config()->columns) . "\n"; - echo str_repeat('-',min(self::config()->columns,max(strlen($title),strlen($subtitle)))) . "\n"; - echo wordwrap($description,self::config()->columns) . "\n\n"; + public function renderInfo($title, $subtitle, $description=false) { + $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; } - public function writeVariable($val, $caller) { - echo PHP_EOL; - echo SS_Cli::text(str_repeat('=', self::config()->columns), 'green'); - echo PHP_EOL; - echo SS_Cli::text($this->formatCaller($caller), 'blue', null, true); - echo PHP_EOL.PHP_EOL; + public function renderVariable($val, $caller) { + $output = PHP_EOL; + $output .= SS_Cli::text(str_repeat('=', self::config()->columns), 'green'); + $output .= PHP_EOL; + $output .= SS_Cli::text($this->formatCaller($caller), 'blue', null, true); + $output .= PHP_EOL.PHP_EOL; if (is_string($val)) { - print_r(wordwrap($val, self::config()->columns)); + $output .= wordwrap($val, self::config()->columns); } else { - print_r($val); + $output .= var_export($val, true); } - echo PHP_EOL; - echo SS_Cli::text(str_repeat('=', self::config()->columns), 'green'); - echo PHP_EOL; + $output .= PHP_EOL; + $output .= SS_Cli::text(str_repeat('=', self::config()->columns), 'green'); + $output .= PHP_EOL; + + return $output; } } diff --git a/dev/DebugView.php b/dev/DebugView.php index 3ee580917..5e73ed807 100644 --- a/dev/DebugView.php +++ b/dev/DebugView.php @@ -11,7 +11,8 @@ * @package framework * @subpackage dev */ -class DebugView extends Object { +class DebugView extends Object +{ /** * Column size to wrap long strings to @@ -100,9 +101,66 @@ class DebugView extends Object { } /** - * Render HTML header for development views + * @deprecated 4.0.0:5.0.0 Use renderHeader() instead */ public function writeHeader() { + Deprecation::notice('4.0', 'Use renderHeader() instead'); + echo $this->renderHeader(); + } + + /** + * @deprecated 4.0.0:5.0.0 Use renderInfo() instead + */ + public function writeInfo($title, $subtitle, $description=false) { + Deprecation::notice('4.0', 'Use renderInfo() instead'); + echo $this->renderInfo($title, $subtitle, $description); + } + + /** + * @deprecated 4.0.0:5.0.0 Use renderFooter() instead + */ + public function writeFooter() { + Deprecation::notice('4.0', 'Use renderFooter() instead'); + echo $this->renderFooter(); + } + + /** + * @deprecated 4.0.0:5.0.0 Use renderError() instead + */ + public function writeError($httpRequest, $errno, $errstr, $errfile, $errline) { + Deprecation::notice('4.0', 'Use renderError() instead'); + echo $this->renderError($httpRequest, $errno, $errstr, $errfile, $errline); + } + + /** + * @deprecated 4.0.0:5.0.0 Use renderSourceFragment() instead + */ + public function writeSourceFragment($lines, $errline) { + Deprecation::notice('4.0', 'Use renderSourceFragment() instead'); + echo $this->renderSourceFragment($lines, $errline); + } + + /** + * @deprecated 4.0.0:5.0.0 Use renderTrace() instead + */ + public function writeTrace($trace) { + Deprecation::notice('4.0', 'Use renderTrace() instead'); + echo $this->renderTrace($trace); + } + + /** + * @deprecated 4.0.0:5.0.0 Use renderVariable() instead + */ + public function writeVariable($val, $caller) { + Deprecation::notice('4.0', 'Use renderVariable() instead'); + echo $this->renderVariable($val, $caller); + } + + /** + * Render HTML header for development views + * @return string + */ + public function renderHeader() { $url = htmlentities( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'], ENT_COMPAT, @@ -115,41 +173,55 @@ class DebugView extends Object { 'css/debug.css' ); - echo '
$description
"; + $output .= "$description
"; } else { - echo $this->Breadcrumbs(); + $output .= $this->Breadcrumbs(); } - echo 'Line $errline in $errfile
"; - echo 'Line $errline in $errfile
"; + $output .= ''; + public function renderSourceFragment($lines, $errline) { + $output = ''; + public function renderTrace($trace) { + $output = 'Source
'; + $output .= ''; foreach($lines as $offset => $line) { $line = htmlentities($line, ENT_COMPAT, 'UTF-8'); if ($offset == $errline) { - echo "$offset $line"; + $output .= "$offset $line"; } else { - echo "$offset $line"; + $output .= "$offset $line"; } } - echo ''; + $output .= ''; + + return $output; } /** - * Write a backtrace + * Render a call track + * + * @param array $trace The debug_backtrace() array + * @return string */ - public function writeTrace($trace) { - echo 'Trace
'; - echo SS_Backtrace::get_rendered_backtrace($trace); - echo 'Trace
'; + $output .= SS_Backtrace::get_rendered_backtrace($trace); + $output .= '
' . $text . '
'; + public function renderParagraph($text) { + return '' . $text . '
'; } /** * Formats the caller of a method * - * @param array $caller + * @param array $caller * @return string */ protected function formatCaller($caller) { @@ -215,14 +302,17 @@ class DebugView extends Object { /** * Outputs a variable in a user presentable way * - * @param object $val - * @param array $caller Caller information + * @param object $val + * @param array $caller Caller information + * @return string */ - public function writeVariable($val, $caller) { - echo '';
- echo "" . $this->formatCaller($caller). " - \n";
- if (is_string($val)) print_r(wordwrap($val, self::config()->columns));
- else print_r($val);
- echo '
';
+ public function renderVariable($val, $caller) {
+ $output = '';
+ $output .= "" . $this->formatCaller($caller). " - \n";
+ if (is_string($val)) $output .= wordwrap($val, self::config()->columns);
+ else $output .= var_export($val, true);
+ $output .= '
';
+
+ return $output;
}
}