Skip to content

Commit

Permalink
FIX Convert slashes in paths when getting list of classes for file/fo…
Browse files Browse the repository at this point in the history
…lder

This is to support the mechanism working on all operating systems where Windows may produce a mix of forward and backward slashes in some paths.
For working with the files it may not be a problem, but for exact string comparison the path delimiters need to be unified.
  • Loading branch information
xini authored and Michal Kleiner committed Mar 1, 2023
1 parent 54fc4ee commit 6585d49
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Core/ClassInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,14 @@ public static function classImplements($className, $interfaceName)
*/
public static function classes_for_file($filePath)
{
$absFilePath = Director::getAbsFile($filePath);
$absFilePath = Convert::slashes(Director::getAbsFile($filePath));
$classManifest = ClassLoader::inst()->getManifest();
$classes = $classManifest->getClasses();
$classNames = $classManifest->getClassNames();

$matchedClasses = [];
foreach ($classes as $lowerClass => $compareFilePath) {
if (strcasecmp($absFilePath ?? '', $compareFilePath ?? '') === 0) {
if (strcasecmp($absFilePath, Convert::slashes($compareFilePath ?? '')) === 0) {
$matchedClasses[$lowerClass] = $classNames[$lowerClass];
}
}
Expand All @@ -324,14 +324,14 @@ public static function classes_for_file($filePath)
*/
public static function classes_for_folder($folderPath)
{
$absFolderPath = Director::getAbsFile($folderPath);
$absFolderPath = Convert::slashes(Director::getAbsFile($folderPath));
$classManifest = ClassLoader::inst()->getManifest();
$classes = $classManifest->getClasses();
$classNames = $classManifest->getClassNames();

$matchedClasses = [];
foreach ($classes as $lowerClass => $compareFilePath) {
if (stripos($compareFilePath ?? '', $absFolderPath ?? '') === 0) {
if (stripos(Convert::slashes($compareFilePath ?? ''), $absFolderPath) === 0) {
$matchedClasses[$lowerClass] = $classNames[$lowerClass];
}
}
Expand Down

0 comments on commit 6585d49

Please sign in to comment.