You are here

public function ClassNotFoundFatalErrorHandler::handleError in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php \Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler::handleError()

Attempts to convert an error into an exception.

Parameters

array $error An array as returned by error_get_last():

FatalErrorException $exception A FatalErrorException instance:

Return value

FatalErrorException|null A FatalErrorException instance if the class is able to convert the error, null otherwise

Overrides FatalErrorHandlerInterface::handleError

File

vendor/symfony/debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php, line 31

Class

ClassNotFoundFatalErrorHandler
ErrorHandler for classes that do not exist.

Namespace

Symfony\Component\Debug\FatalErrorHandler

Code

public function handleError(array $error, FatalErrorException $exception) {
  $messageLen = strlen($error['message']);
  $notFoundSuffix = '\' not found';
  $notFoundSuffixLen = strlen($notFoundSuffix);
  if ($notFoundSuffixLen > $messageLen) {
    return;
  }
  if (0 !== substr_compare($error['message'], $notFoundSuffix, -$notFoundSuffixLen)) {
    return;
  }
  foreach (array(
    'class',
    'interface',
    'trait',
  ) as $typeName) {
    $prefix = ucfirst($typeName) . ' \'';
    $prefixLen = strlen($prefix);
    if (0 !== strpos($error['message'], $prefix)) {
      continue;
    }
    $fullyQualifiedClassName = substr($error['message'], $prefixLen, -$notFoundSuffixLen);
    if (false !== ($namespaceSeparatorIndex = strrpos($fullyQualifiedClassName, '\\'))) {
      $className = substr($fullyQualifiedClassName, $namespaceSeparatorIndex + 1);
      $namespacePrefix = substr($fullyQualifiedClassName, 0, $namespaceSeparatorIndex);
      $message = sprintf('Attempted to load %s "%s" from namespace "%s".', $typeName, $className, $namespacePrefix);
      $tail = ' for another namespace?';
    }
    else {
      $className = $fullyQualifiedClassName;
      $message = sprintf('Attempted to load %s "%s" from the global namespace.', $typeName, $className);
      $tail = '?';
    }
    if ($candidates = $this
      ->getClassCandidates($className)) {
      $tail = array_pop($candidates) . '"?';
      if ($candidates) {
        $tail = ' for e.g. "' . implode('", "', $candidates) . '" or "' . $tail;
      }
      else {
        $tail = ' for "' . $tail;
      }
    }
    $message .= "\nDid you forget a \"use\" statement" . $tail;
    return new ClassNotFoundException($message, $exception);
  }
}