Skip to content

Commit 0344aa6

Browse files
authored
Merge pull request #8216 from colethorsen/feature/fix-file-locator
fix issue where running FileLocator::getClassname() on a directory would cause a PHP error
2 parents 14b7679 + 3ba7ef6 commit 0344aa6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

system/Autoloader/FileLocator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
119119
*/
120120
public function getClassname(string $file): string
121121
{
122+
if (is_dir($file)) {
123+
return '';
124+
}
125+
122126
$php = file_get_contents($file);
123127
$tokens = token_get_all($php);
124128
$dlm = false;

tests/system/Autoloader/FileLocatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,12 @@ public function testGetClassNameFromNonClassFile(): void
312312
$this->locator->getClassname(SYSTEMPATH . 'bootstrap.php')
313313
);
314314
}
315+
316+
public function testGetClassNameFromDirectory(): void
317+
{
318+
$this->assertSame(
319+
'',
320+
$this->locator->getClassname(SYSTEMPATH)
321+
);
322+
}
315323
}

0 commit comments

Comments
 (0)