Skip to content

Commit 8c53ebb

Browse files
committed
In Module::resolveClass throw a different error for class not found (#2185)
* In Module::resolveClass throw a different error for class not found This might help to debug when a class is renamed or moved to a new module. * move the class-exists check up a level * move that up a level for general use * less diff * phpcbf and accept the diff
1 parent 1da6ef4 commit 8c53ebb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/SimpleSAML/Module.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,17 @@ public static function resolveClass(string $id, string $type, ?string $subclass
449449
$className = 'SimpleSAML\\Module\\' . $tmp[0] . $type . $tmp[1];
450450
}
451451

452+
// Check if the class exists to give a more informative error
453+
// for cases where modules might have been moved or renamed.
454+
// Otherwise a not subclass of error would be thrown for a class
455+
// that does not exist.
456+
if (!class_exists($className, true)) {
457+
throw new Exception(
458+
'Could not resolve \'' . $id . '\': The class \'' . $className
459+
. '\' does not exist.',
460+
);
461+
}
462+
452463
if ($subclass !== null && !is_subclass_of($className, $subclass)) {
453464
throw new Exception(
454465
'Could not resolve \'' . $id . '\': The class \'' . $className

0 commit comments

Comments
 (0)