function DebugClassLoader::checkClass
2 calls to DebugClassLoader::checkClass()
- DebugClassLoader::checkAnnotations in vendor/
symfony/ error-handler/ DebugClassLoader.php - DebugClassLoader::loadClass in vendor/
symfony/ error-handler/ DebugClassLoader.php - Loads the given class or interface.
File
-
vendor/
symfony/ error-handler/ DebugClassLoader.php, line 314
Class
- DebugClassLoader
- Autoloader checking if the class is really defined in the file found.
Namespace
Symfony\Component\ErrorHandlerCode
private function checkClass(string $class, ?string $file = null) : void {
$exists = null === $file || class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false);
if (null !== $file && $class && '\\' === $class[0]) {
$class = substr($class, 1);
}
if ($exists) {
if (isset(self::$checkedClasses[$class])) {
return;
}
self::$checkedClasses[$class] = true;
$refl = new \ReflectionClass($class);
if (null === $file && $refl->isInternal()) {
return;
}
$name = $refl->getName();
if ($name !== $class && 0 === strcasecmp($name, $class)) {
throw new \RuntimeException(\sprintf('Case mismatch between loaded and declared class names: "%s" vs "%s".', $class, $name));
}
$deprecations = $this->checkAnnotations($refl, $name);
foreach ($deprecations as $message) {
@trigger_error($message, \E_USER_DEPRECATED);
}
}
if (!$file) {
return;
}
if (!$exists) {
if (str_contains($class, '/')) {
throw new \RuntimeException(\sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\\" in PHP, not "/".', $class));
}
throw new \RuntimeException(\sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
if (self::$caseCheck && ($message = $this->checkCase($refl, $file, $class))) {
throw new \RuntimeException(\sprintf('Case mismatch between class and real file names: "%s" vs "%s" in "%s".', $message[0], $message[1], $message[2]));
}
}