Neos\Flow\Error\Debugger::getBacktraceCode PHP Метод

getBacktraceCode() публичный статический Метод

Renders some backtrace
public static getBacktraceCode ( array $trace, boolean $includeCode = true, boolean $plaintext = false ) : string
$trace array The trace
$includeCode boolean Include code snippet
$plaintext boolean
Результат string Backtrace information
    public static function getBacktraceCode(array $trace, $includeCode = true, $plaintext = false)
    {
        $backtraceCode = '';
        if (count($trace)) {
            foreach ($trace as $index => $step) {
                if ($plaintext) {
                    $class = isset($step['class']) ? $step['class'] . '::' : '';
                } else {
                    $class = isset($step['class']) ? $step['class'] . '<span style="color:white;">::</span>' : '';
                }
                $arguments = '';
                if (isset($step['args']) && is_array($step['args'])) {
                    foreach ($step['args'] as $argument) {
                        if ($plaintext) {
                            $arguments .= strlen($arguments) === 0 ? '' : ', ';
                        } else {
                            $arguments .= strlen($arguments) === 0 ? '' : '<span style="color:white;">,</span> ';
                        }
                        if (is_object($argument)) {
                            if ($plaintext) {
                                $arguments .= get_class($argument);
                            } else {
                                $arguments .= '<span style="color:#FF8700;"><em>' . get_class($argument) . '</em></span>';
                            }
                        } elseif (is_string($argument)) {
                            $preparedArgument = strlen($argument) < 100 ? $argument : substr($argument, 0, 50) . '…' . substr($argument, -50);
                            $preparedArgument = htmlspecialchars($preparedArgument);
                            if ($plaintext) {
                                $arguments .= '"' . $argument . '"';
                            } else {
                                $preparedArgument = str_replace('…', '<span style="color:white;">…</span>', $preparedArgument);
                                $preparedArgument = str_replace("\n", '<span style="color:white;">⏎</span>', $preparedArgument);
                                $arguments .= '"<span style="color:#FF8700;" title="' . htmlspecialchars($argument) . '">' . $preparedArgument . '</span>"';
                            }
                        } elseif (is_numeric($argument)) {
                            if ($plaintext) {
                                $arguments .= (string) $argument;
                            } else {
                                $arguments .= '<span style="color:#FF8700;">' . (string) $argument . '</span>';
                            }
                        } elseif (is_bool($argument)) {
                            if ($plaintext) {
                                $arguments .= $argument === true ? 'TRUE' : 'FALSE';
                            } else {
                                $arguments .= '<span style="color:#FF8700;">' . ($argument === true ? 'TRUE' : 'FALSE') . '</span>';
                            }
                        } elseif (is_array($argument)) {
                            if ($plaintext) {
                                $arguments .= 'array|' . count($argument) . '|';
                            } else {
                                $arguments .= sprintf('<span style="color:#FF8700;" title="%s"><em>array|%d|</em></span>', htmlspecialchars(self::renderArrayDump($argument, 0, true)), count($argument));
                            }
                        } else {
                            if ($plaintext) {
                                $arguments .= gettype($argument);
                            } else {
                                $arguments .= '<span style="color:#FF8700;"><em>' . gettype($argument) . '</em></span>';
                            }
                        }
                    }
                }
                if ($plaintext) {
                    $backtraceCode .= count($trace) - $index . ' ' . $class . $step['function'] . '(' . $arguments . ')';
                } else {
                    $backtraceCode .= '<pre style="color:#69A550; background-color: #414141; padding: 4px 2px 4px 2px;">';
                    $backtraceCode .= '<span style="color:white;">' . (count($trace) - $index) . '</span> ' . $class . $step['function'] . '<span style="color:white;">(' . $arguments . ')</span>';
                    $backtraceCode .= '</pre>';
                }
                if (isset($step['file']) && $includeCode) {
                    $backtraceCode .= self::getCodeSnippet($step['file'], $step['line'], $plaintext);
                }
                if ($plaintext) {
                    $backtraceCode .= PHP_EOL;
                } else {
                    $backtraceCode .= '<br />';
                }
            }
        }
        return $backtraceCode;
    }

Usage Example

    /**
     * Returns the statically rendered exception message
     *
     * @param integer $statusCode
     * @param object $exception \Exception or \Throwable
     * @return void
     */
    protected function renderStatically($statusCode, $exception)
    {
        $statusMessage = Response::getStatusMessageByCode($statusCode);
        $exceptionHeader = '';
        while (true) {
            $pathPosition = strpos($exception->getFile(), 'Packages/');
            $filePathAndName = $pathPosition !== false ? substr($exception->getFile(), $pathPosition) : $exception->getFile();
            $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
            $exceptionMessageParts = $this->splitExceptionMessage($exception->getMessage());
            $exceptionHeader .= '<h2 class="ExceptionSubject">' . $exceptionCodeNumber . htmlspecialchars($exceptionMessageParts['subject']) . '</h2>';
            if ($exceptionMessageParts['body'] !== '') {
                $exceptionHeader .= '<p class="ExceptionBody">' . nl2br(htmlspecialchars($exceptionMessageParts['body'])) . '</p>';
            }
            $exceptionHeader .= '
				<span class="ExceptionProperty">' . get_class($exception) . '</span> thrown in file<br />
				<span class="ExceptionProperty">' . $filePathAndName . '</span> in line
				<span class="ExceptionProperty">' . $exception->getLine() . '</span>.<br />';
            if ($exception instanceof FlowException) {
                $exceptionHeader .= '<span class="ExceptionProperty">Reference code: ' . $exception->getReferenceCode() . '</span><br />';
            }
            if ($exception->getPrevious() === null) {
                break;
            }
            $exceptionHeader .= '<br /><div style="width: 100%; background-color: #515151; color: white; padding: 2px; margin: 0 0 6px 0;">Nested Exception</div>';
            $exception = $exception->getPrevious();
        }
        $backtraceCode = Debugger::getBacktraceCode($exception->getTrace());
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
				"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
			<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
			<head>
				<title>' . $statusCode . ' ' . $statusMessage . '</title>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<style>
					.ExceptionSubject {
						margin: 0;
						padding: 0;
						font-size: 15px;
						color: #BE0027;
					}
					.ExceptionBody {
						padding: 10px;
						margin: 10px;
						color: black;
						background: #DDD;
					}
					.ExceptionProperty {
						color: #101010;
					}
					pre {
						margin: 0;
						font-size: 11px;
						color: #515151;
						background-color: #D0D0D0;
						padding-left: 30px;
					}
				</style>
			</head>
			<div style="
					position: absolute;
					left: 10px;
					background-color: #B9B9B9;
					outline: 1px solid #515151;
					color: #515151;
					font-family: Arial, Helvetica, sans-serif;
					font-size: 12px;
					margin: 10px;
					padding: 0;
				">
				<div style="width: 100%; background-color: #515151; color: white; padding: 2px; margin: 0 0 6px 0;">Uncaught Exception in Flow</div>
				<div style="width: 100%; padding: 2px; margin: 0 0 6px 0;">
					' . $exceptionHeader . '
					<br />
					' . $backtraceCode . '
				</div>
			</div>
		';
    }
All Usage Examples Of Neos\Flow\Error\Debugger::getBacktraceCode