You are here

private function ClassNotFoundFatalErrorHandler::convertFileToClass in Zircon Profile 8

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

Parameters

string $path:

string $file:

string $prefix:

Return value

string|null

1 call to ClassNotFoundFatalErrorHandler::convertFileToClass()
ClassNotFoundFatalErrorHandler::findClassInPath in vendor/symfony/debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php

File

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

Class

ClassNotFoundFatalErrorHandler
ErrorHandler for classes that do not exist.

Namespace

Symfony\Component\Debug\FatalErrorHandler

Code

private function convertFileToClass($path, $file, $prefix) {
  $candidates = array(
    // namespaced class
    $namespacedClass = str_replace(array(
      $path . DIRECTORY_SEPARATOR,
      '.php',
      '/',
    ), array(
      '',
      '',
      '\\',
    ), $file),
    // namespaced class (with target dir)
    $prefix . $namespacedClass,
    // namespaced class (with target dir and separator)
    $prefix . '\\' . $namespacedClass,
    // PEAR class
    str_replace('\\', '_', $namespacedClass),
    // PEAR class (with target dir)
    str_replace('\\', '_', $prefix . $namespacedClass),
    // PEAR class (with target dir and separator)
    str_replace('\\', '_', $prefix . '\\' . $namespacedClass),
  );
  if ($prefix) {
    $candidates = array_filter($candidates, function ($candidate) use ($prefix) {
      return 0 === strpos($candidate, $prefix);
    });
  }

  // We cannot use the autoloader here as most of them use require; but if the class
  // is not found, the new autoloader call will require the file again leading to a
  // "cannot redeclare class" error.
  foreach ($candidates as $candidate) {
    if ($this
      ->classExists($candidate)) {
      return $candidate;
    }
  }
  require_once $file;
  foreach ($candidates as $candidate) {
    if ($this
      ->classExists($candidate)) {
      return $candidate;
    }
  }
}