From 43e035864bbf1d4e6c76b6ed9086e2517711b2f1 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 6 Oct 2023 10:30:08 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20findQualifiedNameFromPath()=20return?= =?UTF-8?q?s=20FQCN=20with=20leading=20=E2=80=9C\"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FQCN should not start with “\". ::class returns FQCN without leading "\". --- system/Autoloader/FileLocator.php | 2 +- tests/system/Autoloader/FileLocatorTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index bc18bd31b980..71be43b5aa8c 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -273,7 +273,7 @@ public function findQualifiedNameFromPath(string $path) } if (mb_strpos($path, $namespace['path']) === 0) { - $className = '\\' . $namespace['prefix'] . '\\' . + $className = $namespace['prefix'] . '\\' . ltrim(str_replace( '/', '\\', diff --git a/tests/system/Autoloader/FileLocatorTest.php b/tests/system/Autoloader/FileLocatorTest.php index 1cf32cfa5ad1..0d084280f520 100644 --- a/tests/system/Autoloader/FileLocatorTest.php +++ b/tests/system/Autoloader/FileLocatorTest.php @@ -278,7 +278,7 @@ public function testListFilesWithoutPath(): void public function testFindQNameFromPathSimple(): void { $ClassName = $this->locator->findQualifiedNameFromPath(SYSTEMPATH . 'HTTP/Header.php'); - $expected = '\\' . Header::class; + $expected = Header::class; $this->assertSame($expected, $ClassName); } From f51c542f7f7d77ab175c5d0d9ed11487cf39c8da Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 6 Oct 2023 10:33:36 +0900 Subject: [PATCH 2/3] style: break long line --- system/Autoloader/FileLocator.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 71be43b5aa8c..6f241e847be3 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -274,11 +274,14 @@ public function findQualifiedNameFromPath(string $path) if (mb_strpos($path, $namespace['path']) === 0) { $className = $namespace['prefix'] . '\\' . - ltrim(str_replace( + ltrim( + str_replace( '/', '\\', mb_substr($path, mb_strlen($namespace['path'])) - ), '\\'); + ), + '\\' + ); // Remove the file extension (.php) $className = mb_substr($className, 0, -4); From 4e6b1bbfe1335a7aab506ed7e8756d24e5c9a0fa Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 6 Oct 2023 10:50:23 +0900 Subject: [PATCH 3/3] docs: add changelog and upgrade_450 --- user_guide_src/source/changelogs/v4.5.0.rst | 2 ++ user_guide_src/source/installation/upgrade_450.rst | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index 3f509d73431f..320c961bb8e1 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -33,6 +33,8 @@ Others - **Logger:** The :php:func:`log_message()` function and the logger methods in ``CodeIgniter\Log\Logger`` now do not return ``bool`` values. The return types have been fixed to ``void`` to follow the PSR-3 interface. +- **Autoloader:** The prefix ``\`` in the fully qualified classname returned by + ``FileLocator::findQualifiedNameFromPath()`` has been removed. Interface Changes ================= diff --git a/user_guide_src/source/installation/upgrade_450.rst b/user_guide_src/source/installation/upgrade_450.rst index 7a4fbc0b29da..8b91b67ae77e 100644 --- a/user_guide_src/source/installation/upgrade_450.rst +++ b/user_guide_src/source/installation/upgrade_450.rst @@ -72,6 +72,14 @@ reversed. Previous: route1 → route2 → filter1 → filter2 Now: route2 → route1 → filter2 → filter1 +FileLocator::findQualifiedNameFromPath() +======================================== + +In previous versions, ``FileLocator::findQualifiedNameFromPath()`` returns Fully +Qualified Classnames with a leading ``\``. Now the leading ``\`` has been removed. + +If you have code that expects a leading ``\``, fix it. + Removed Deprecated Items ========================