Skip to content

Commit

Permalink
Merge pull request #8216 from colethorsen/feature/fix-file-locator
Browse files Browse the repository at this point in the history
fix issue where running FileLocator::getClassname() on a directory would cause a PHP error
  • Loading branch information
kenjis authored Nov 19, 2023
2 parents 14b7679 + 3ba7ef6 commit 0344aa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
*/
public function getClassname(string $file): string
{
if (is_dir($file)) {
return '';
}

$php = file_get_contents($file);
$tokens = token_get_all($php);
$dlm = false;
Expand Down
8 changes: 8 additions & 0 deletions tests/system/Autoloader/FileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,12 @@ public function testGetClassNameFromNonClassFile(): void
$this->locator->getClassname(SYSTEMPATH . 'bootstrap.php')
);
}

public function testGetClassNameFromDirectory(): void
{
$this->assertSame(
'',
$this->locator->getClassname(SYSTEMPATH)
);
}
}

0 comments on commit 0344aa6

Please sign in to comment.