Skip to content

Commit

Permalink
Add stream wrapper support
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHenryIE committed Feb 1, 2025
1 parent e63346d commit 526afb6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/ClassMapGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,20 @@ public function scanPaths($path, ?string $excluded = null, string $autoloadType
continue;
}

if (!self::isAbsolutePath($filePath)) {
if (!self::isAbsolutePath($filePath) && !self::isStreamWrapper($filePath)) {
$filePath = $cwd . '/' . $filePath;
$filePath = self::normalizePath($filePath);
} else {
} elseif(!self::isStreamWrapper($filePath)) {
$filePath = Preg::replace('{[\\\\/]{2,}}', '/', $filePath);
}

if ('' === $filePath) {
throw new \LogicException('Got an empty $filePath for '.$file->getPathname());
}

$realPath = realpath($filePath);
$realPath = !self::isStreamWrapper($filePath)
? realpath($filePath)
: $filePath;

// fallback just in case but this really should not happen
if (false === $realPath) {
Expand Down Expand Up @@ -276,6 +278,22 @@ private static function isAbsolutePath(string $path)
return strpos($path, '/') === 0 || substr($path, 1, 1) === ':' || strpos($path, '\\\\') === 0;
}

/**
* Determine if a path is a stream wrapper. All stream wrappers are absolute paths.
*
* @param string $path
*
* @return bool
*/
private static function isStreamWrapper(string $path) {
foreach(stream_get_wrappers() as $wrapper) {
if (strpos($path, $wrapper.'://') === 0) {
return true;
}
}
return false;
}

/**
* Normalize a path. This replaces backslashes with slashes, removes ending
* slash and collapses redundant separators and up-level references.
Expand Down

0 comments on commit 526afb6

Please sign in to comment.