Skip to content

Commit c11ae11

Browse files
Support absolute paths in composer autoload sections (#171)
1 parent e64aa7f commit c11ae11

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/ComposerJson.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ private function extractAutoloadPaths(string $basePath, array $autoload, bool $i
128128
}
129129

130130
foreach ($paths as $path) {
131-
$absolutePath = $basePath . '/' . $path;
131+
if (Path::isAbsolute($path)) {
132+
$absolutePath = $path;
133+
} else {
134+
$absolutePath = $basePath . '/' . $path;
135+
}
132136

133137
if (strpos($path, '*') !== false) { // https://getcomposer.org/doc/04-schema.md#classmap
134138
$globPaths = glob($absolutePath);

tests/ComposerJsonTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function testComposerJson(): void
4141
realpath(__DIR__ . '/data/not-autoloaded/composer/dir2/file1.php') => false,
4242
realpath(__DIR__ . '/data/not-autoloaded/composer/dir1') => false,
4343
realpath(__DIR__ . '/data/not-autoloaded/composer/dir2') => false,
44+
DIRECTORY_SEPARATOR . 'absolute' . DIRECTORY_SEPARATOR . 'dir' => false,
4445
],
4546
$composerJson->autoloadPaths
4647
);

tests/data/not-autoloaded/composer/sample.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
},
99
"autoload": {
1010
"classmap": [
11-
"dir*"
11+
"dir*",
12+
"/absolute/dir"
1213
],
1314
"files": [
1415
"dir2/file1.php"

0 commit comments

Comments
 (0)