コード例 #1
0
 /**
  * Called at script shutdown if the shutdown is because of a fatal error.
  *
  * @param int    $errorLevel   The error code {@uses E_*}
  * @param string $message      The error message.
  * @param string $file         The file where the error occured.
  * @param int    $line         The line in the file where the error occured.
  * @param string $errorId      The internal ID of the error.
  *
  * @return void
  */
 public function handleShutdown($errorLevel, $message, $file, $line, $errorId)
 {
     $helper = new ErrorHandlerHelper();
     $errorLevelDescription = $helper->getPhpErrorLevelDescription($errorLevel);
     $errorMessage = '[' . $errorLevelDescription . '(' . $errorLevel . ')]: ' . $message . ' on line ' . $line . ' in ' . $file;
     $message = Application::getInstance()->getDiContainer()->getErrorLogMessage();
     $message->set($errorMessage, $errorLevelDescription, $errorId, $helper->getLogPriorityForErrorLevel($errorLevel));
     $this->logger->log($message);
 }
コード例 #2
0
 /**
  * Called at script shutdown if the shutdown is because of a fatal error.
  *
  * @param int    $errorLevel   The error code {@uses E_*}
  * @param string $message      The error message.
  * @param string $file         The file where the error occured.
  * @param int    $line         The line in the file where the error occured.
  * @param string $errorId      The internal ID of the error.
  *
  * @return void
  */
 public function handleShutdown($errorLevel, $message, $file, $line, $errorId)
 {
     if (false !== $this->storage->get($errorId)) {
         // Only save the debug info, if it's not already saved
         return;
     }
     $helper = new ErrorHandlerHelper();
     $errorLevelDescription = $helper->getPhpErrorLevelDescription($errorLevel);
     $errorMessage = '[' . $errorLevelDescription . '(' . $errorLevel . ')]: ' . $message . ' on line ' . $line . ' in ' . $file;
     $this->storage->set($errorId, $this->getDebugData($errorId, $errorMessage));
 }
コード例 #3
0
    /**
     * Creates a displayable HTML from the given error, and stores it.
     *
     * @param \YapepBase\Debugger\Item\ErrorItem $error   The error item.
     *
     * @return string
     */
    public function getFormattedError(ErrorItem $error)
    {
        static $errorHandlerHelper;
        if (empty($errorHandlerHelper)) {
            $errorHandlerHelper = new ErrorHandlerHelper();
        }
        $errorData = $error->getData();
        $file = $this->viewDo->escape($errorData[ErrorItem::FIELD_FILE]);
        $line = $this->viewDo->escape($errorData[ErrorItem::FIELD_LINE]);
        $id = uniqid($this->viewDo->escape($errorData[ErrorItem::LOCAL_FIELD_ID]));
        $message = '[' . $this->viewDo->escape($errorHandlerHelper->getPhpErrorLevelDescription($errorData[ErrorItem::LOCAL_FIELD_CODE])) . '] ' . $this->viewDo->escape($errorData[ErrorItem::LOCAL_FIELD_MESSAGE]);
        $source = FileHelper::getEnvironment($file, $line, 5);
        $firstLine = key($source);
        $errorHtml = '
			<div class="yapep-debug-error-item">
				<p class="yapep-debug-clickable" onclick="Yapep.toggle(\'error-' . $id . '\'); return false;">
					' . $message . '<br/>
					in <var>' . $file . '</var>, <u>line ' . $line . '</u>
				</p>
			';
        if (!empty($errorData[ErrorItem::LOCAL_FIELD_DEBUG_DATA_URL])) {
            $errorHtml .= '<p><a href="' . $errorData[ErrorItem::LOCAL_FIELD_DEBUG_DATA_URL] . '" target="_blank">Debug data</a></p>';
        }
        $errorHtml .= '<div class="yapep-debug-container" id="yapep-debug-error-' . $id . '">
					<h3>Source code</h3>
					<ol start="' . $firstLine . '" class="yapep-debug-code">
		';
        foreach ($source as $lineNumber => $codeLine) {
            if ($codeLine === '') {
                $codeLine = ' ';
            }
            $codeLine = str_replace('&lt;?php&nbsp;', '', highlight_string('<?php ' . $codeLine, true));
            if ($line > $lineNumber) {
                foreach ($errorData[ErrorItem::LOCAL_FIELD_CONTEXT] as $varName => $value) {
                    if (is_scalar($value) || is_array($value)) {
                        $tooltip = $this->viewDo->escape(gettype($value) . ': ' . print_r($value, true));
                    } elseif ($value instanceof Exception) {
                        $tooltip = $this->viewDo->escape(get_class($value) . ': ' . $value->getMessage());
                    } elseif (is_object($value) && method_exists($value, '__toString')) {
                        $tooltip = $this->viewDo->escape(get_class($value) . ': ' . $value->__toString());
                    } else {
                        $tooltip = $this->viewDo->escape(strtoupper(gettype($value)));
                    }
                    $codeLine = preg_replace('#(?<!::)\\$' . $varName . '\\b#', '<var title="' . htmlspecialchars($tooltip) . '">' . '$' . $varName . '</var>', $codeLine);
                }
            }
            $errorHtml .= '<li class="' . ($lineNumber % 2 ? 'odd ' : '') . ($lineNumber == $line ? 'yapep-debug-code-highlight' : '') . '">' . $codeLine . '</li>';
        }
        $errorHtml .= '</ol>';
        $errorHtml .= '</div>';
        $errorHtml .= '</div>';
        return $errorHtml;
    }