Skip to content

Commit 5210e5e

Browse files
authored
Merge pull request #8010 from kenjis/fix-FileLocator-findQualifiedNameFromPath
fix: `FileLocator::findQualifiedNameFromPath()` behavior
2 parents 1a6d2a9 + 4e6b1bb commit 5210e5e

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

system/Autoloader/FileLocator.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,15 @@ public function findQualifiedNameFromPath(string $path)
273273
}
274274

275275
if (mb_strpos($path, $namespace['path']) === 0) {
276-
$className = '\\' . $namespace['prefix'] . '\\' .
277-
ltrim(str_replace(
276+
$className = $namespace['prefix'] . '\\' .
277+
ltrim(
278+
str_replace(
278279
'/',
279280
'\\',
280281
mb_substr($path, mb_strlen($namespace['path']))
281-
), '\\');
282+
),
283+
'\\'
284+
);
282285

283286
// Remove the file extension (.php)
284287
$className = mb_substr($className, 0, -4);

tests/system/Autoloader/FileLocatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function testListFilesWithoutPath(): void
278278
public function testFindQNameFromPathSimple(): void
279279
{
280280
$ClassName = $this->locator->findQualifiedNameFromPath(SYSTEMPATH . 'HTTP/Header.php');
281-
$expected = '\\' . Header::class;
281+
$expected = Header::class;
282282

283283
$this->assertSame($expected, $ClassName);
284284
}

user_guide_src/source/changelogs/v4.5.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Others
3333
- **Logger:** The :php:func:`log_message()` function and the logger methods in
3434
``CodeIgniter\Log\Logger`` now do not return ``bool`` values. The return types
3535
have been fixed to ``void`` to follow the PSR-3 interface.
36+
- **Autoloader:** The prefix ``\`` in the fully qualified classname returned by
37+
``FileLocator::findQualifiedNameFromPath()`` has been removed.
3638

3739
Interface Changes
3840
=================

user_guide_src/source/installation/upgrade_450.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ reversed.
7272
Previous: route1 → route2 → filter1 → filter2
7373
Now: route2 → route1 → filter2 → filter1
7474

75+
FileLocator::findQualifiedNameFromPath()
76+
========================================
77+
78+
In previous versions, ``FileLocator::findQualifiedNameFromPath()`` returns Fully
79+
Qualified Classnames with a leading ``\``. Now the leading ``\`` has been removed.
80+
81+
If you have code that expects a leading ``\``, fix it.
82+
7583
Removed Deprecated Items
7684
========================
7785

0 commit comments

Comments
 (0)