From 9f850f79d9e5cd81a59ff04131133741f84f9fa1 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 13 Apr 2024 21:53:03 +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/Config/BaseService.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index 2f8df2a35420..cd770dc667ed 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -389,8 +389,15 @@ protected static function buildServicesCache(): void $locator = static::locator(); $files = $locator->search('Config/Services'); + $systemPath = static::autoloader()->getNamespace('CodeIgniter')[0]; + // Get instances of all service classes and cache them locally. foreach ($files as $file) { + // Does not search `CodeIgniter` namespace to prevent from loading twice. + if (str_starts_with($file, $systemPath)) { + continue; + } + $classname = $locator->findQualifiedNameFromPath($file); if ($classname === false) {