Zum Hauptinhalt springen

Vertippt?^800

Falscher Link?^800

Alter Link?^800

Auf jeden Fall bist du hier nicht richtig!^800

Fehler 404!

namespace TYPO3\CMS\Core\Error;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class ErrorHandler implements ErrorHandlerInterface, LoggerAwareInterface
{
  use LoggerAwareTrait;
  protected$exceptionalErrors = 0;
  protected$errorHandlerErrors = 0;
  protected$debugMode = false;
  public function __construct($errorHandlerErrors)
  {
    $excludedErrors = E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR;
    $this->errorHandlerErrors = $errorHandlerErrors& ~$excludedErrors;
    set_error_handler([$this, 'handleError'], $this->errorHandlerErrors);
  }
  public function setExceptionalErrors($exceptionalErrors)
  {
    $exceptionalErrors = (int)$exceptionalErrors;
    $this->exceptionalErrors = $exceptionalErrors& ~E_USER_DEPRECATED;
  }
  public function setDebugMode($debugMode)
  {
    $this->debugMode = (bool)$debugMode;
  }
  public function handleError($errorLevel, $errorMessage, $errorFile, $errorLine)
  {
    $shouldHandleErrorLevel = (bool)($this->errorHandlerErrors & $errorLevel);
    if (error_reporting() === 0 || !$shouldHandleErrorLevel) {
    return true;
    }
    $errorLevels = [
    E_WARNING => 'PHP Warning',
    E_NOTICE => 'PHP Notice',
    E_USER_ERROR => 'PHP User Error',
    E_USER_WARNING => 'PHP User Warning',
    E_USER_NOTICE => 'PHP User Notice',
    E_STRICT => 'PHP Runtime Notice',
    E_RECOVERABLE_ERROR => 'PHP Catchable Fatal Error',
    E_USER_DEPRECATED => 'TYPO3 Deprecation Notice',
    E_DEPRECATED => 'PHP Runtime Deprecation Notice'
    ];
    $message = $errorLevels[$errorLevel] . ': ' . $errorMessage . ' in ' . $errorFile . ' line ' . $errorLine;
    if ($errorLevel & $this->exceptionalErrors) {
    throw new Exception($message, 1476107295);
    }
    switch ($errorLevel) {
    case E_USER_ERROR:
    case E_RECOVERABLE_ERROR:
      $severity = 2;
      break;
    case E_USER_WARNING:
    case E_WARNING:
      $flashMessageSeverity = FlashMessage::WARNING;
      $severity = 1;
      break;
    default:
      $flashMessageSeverity = FlashMessage::NOTICE;
      $severity = 0;
    }
    $logTitle = 'Core: Error handler (' . TYPO3_MODE . ')';
    $message = $logTitle . ': ' . $message;
    if ($errorLevel === E_USER_DEPRECATED) {
    $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger('TYPO3.CMS.deprecations');
    $logger->notice($message);
    return true;
    }
    if ($this->logger) {
    $this->logger->log(LogLevel::NOTICE - $severity, $message);
    }
    $timeTracker = $this->getTimeTracker();
    if (is_object($timeTracker)) {
    $timeTracker->setTSlogMessage($message, $severity + 1);
    }
    if ($errorLevel & $GLOBALS['TYPO3_CONF_VARS']['SYS']['belogErrorReporting']) {
    try {
      $this->writeLog($message, $severity);
    } catch (\Exception $e) {
    }
    }
    if ($severity === 2) {
    return false;
    }
    if ($this->debugMode) {
    $flashMessage = GeneralUtility::makeInstance(
      \TYPO3\CMS\Core\Messaging\FlashMessage::class,
      $message,
      $errorLevels[$errorLevel],
      $flashMessageSeverity
    );
    $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
    $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
    $defaultFlashMessageQueue->enqueue($flashMessage);
    }
    return true;
  }
  protected function writeLog($logMessage, $severity)
  {
    $connection = GeneralUtility::makeInstance(ConnectionPool::class)
    ->getConnectionForTable('sys_log');
    if ($connection->isConnected()) {
    $userId = 0;
    $workspace = 0;
    $data = [];
    $backendUser = $this->getBackendUser();
    if (is_object($backendUser)) {
      if (isset($backendUser->user['uid'])) {
      $userId = $backendUser->user['uid'];
      }
      if (isset($backendUser->workspace)) {
      $workspace = $backendUser->workspace;
      }
      if (!empty($backendUser->user['ses_backuserid'])) {
      $data['originalUser'] = $backendUser->user['ses_backuserid'];
      }
    }
    $connection->insert(
      'sys_log',
      [
        'userid' => $userId,
        'type' => 5,
        'action' => 0,
        'error' => $severity,
        'details_nr' => 0,
        'details' => str_replace('%', '%%', $logMessage),
        'log_data' =>empty($data) ? '' : serialize($data),
        'IP' => (string)GeneralUtility::getIndpEnv('REMOTE_ADDR'),
        'tstamp' => $GLOBALS['EXEC_TIME'],
        'workspace' => $workspace
      ]
    );
    }
    }
  protected function getTimeTracker()
  {
    return GeneralUtility::makeInstance(TimeTracker::class);
  }
  protected function getBackendUser()
  {
    return $GLOBALS['BE_USER'];
  }
}