From 5e6979b52ae0dc71107ce6166748a1d80618c882 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 10 Apr 2024 10:39:44 +0900 Subject: [PATCH] fix: Cannot declare class Shield\Config\Auth, because the name is already in use See https://github.com/codeigniter4/shield/issues/1091 --- system/Autoloader/FileLocator.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 97da0fa275eb..14b9a1366ab4 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -28,6 +28,13 @@ class FileLocator implements FileLocatorInterface */ protected $autoloader; + /** + * List of classnames that did not exist. + * + * @var list + */ + private array $invalidClassnames = []; + public function __construct(Autoloader $autoloader) { $this->autoloader = $autoloader; @@ -288,14 +295,20 @@ public function findQualifiedNameFromPath(string $path) ), '\\' ); - // Remove the file extension (.php) $className = mb_substr($className, 0, -4); + if (in_array($className, $this->invalidClassnames, true)) { + continue; + } + // Check if this exists if (class_exists($className)) { return $className; } + + // If the class does not exist, it is an invalid classname. + $this->invalidClassnames[] = $className; } }