From 90748d21f7b4bc35491f79c12de783735166d955 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 13 Apr 2024 21:26:51 +0900 Subject: [PATCH] fix: Cannot declare class CodeIgniter\Config\Services, because the name is already in use See https://github.com/codeigniter4/CodeIgniter4/pull/8745#issuecomment-2052569997 --- system/Autoloader/FileLocator.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 14b9a1366ab4..f4ebbc7d5e60 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -265,8 +265,10 @@ protected function getNamespaces() } /** - * Find the qualified name of a file according to - * the namespace of the first matched namespace path. + * Find the qualified name of a file according to the namespace of the first + * matched namespace path. + * + * This does not find files in `CodeIgniter` namespace. * * @return false|string The qualified name or false if the path is not found */ @@ -274,6 +276,12 @@ public function findQualifiedNameFromPath(string $path) { $path = realpath($path) ?: $path; + // Does not search `CodeIgniter` namespace to prevent from loading twice. + $systemPath = $this->autoloader->getNamespace('CodeIgniter')[0]; + if (str_starts_with($path, $systemPath)) { + return false; + } + if (! is_file($path)) { return false; }