Skip to content

Commit

Permalink
Merge pull request #8010 from kenjis/fix-FileLocator-findQualifiedNam…
Browse files Browse the repository at this point in the history
…eFromPath

fix: `FileLocator::findQualifiedNameFromPath()` behavior
  • Loading branch information
kenjis authored Oct 13, 2023
2 parents 1a6d2a9 + 4e6b1bb commit 5210e5e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
9 changes: 6 additions & 3 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,15 @@ public function findQualifiedNameFromPath(string $path)
}

if (mb_strpos($path, $namespace['path']) === 0) {
$className = '\\' . $namespace['prefix'] . '\\' .
ltrim(str_replace(
$className = $namespace['prefix'] . '\\' .
ltrim(
str_replace(
'/',
'\\',
mb_substr($path, mb_strlen($namespace['path']))
), '\\');
),
'\\'
);

// Remove the file extension (.php)
$className = mb_substr($className, 0, -4);
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Autoloader/FileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=================
Expand Down
8 changes: 8 additions & 0 deletions user_guide_src/source/installation/upgrade_450.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
========================

Expand Down

0 comments on commit 5210e5e

Please sign in to comment.