Skip to content

Commit 1025b81

Browse files
committed
Support short name prefixes
1 parent 29def61 commit 1025b81

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

lib/Adapter/Composer/Psr0NameInflector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ final class Psr0NameInflector implements NameInflector
99
{
1010
public function inflectToRelativePath(string $prefix, ClassName $className, string $mappedPath): FilePath
1111
{
12+
if (substr($prefix, -1) !== '\\' && $className->beginsWith($prefix)) {
13+
$className = substr($className, strlen($prefix));
14+
}
15+
1216
$relativePath = str_replace('\\', '/', $className).'.php';
17+
1318
return FilePath::fromParts([$mappedPath, $relativePath]);
1419
}
1520

lib/Domain/FilePath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ final class FilePath
1010

1111
private function __construct(string $path)
1212
{
13+
$path = Path::canonicalize($path);
1314
$this->path = $path;
1415
}
1516

@@ -25,7 +26,6 @@ public function __toString()
2526

2627
public static function fromString($path)
2728
{
28-
$path = Path::canonicalize($path);
2929
return new self($path);
3030
}
3131

tests/Integration/Composer/ComposerClassToFileTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public function testPsr0Fallback()
9393
$this->assertClassNameToFilePath('Acme\\Test\\Class', [ 'psr0/Acme/Test/Class.php' ]);
9494
}
9595

96+
/**
97+
* @testdox PSR-0 short name prefix
98+
*/
99+
public function testPsr0ShortNamePrefix()
100+
{
101+
$this->loadExample('psr0-short-prefix.json');
102+
$this->assertClassNameToFilePath('Twig_Extension', [ 'psr0/twig/Extension.php' ]);
103+
}
104+
96105
/**
97106
* @testdox PSR-4 fallback
98107
*/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "dantleech/basic",
3+
"authors": [
4+
{
5+
"name": "dantleech",
6+
"email": "dan.t.leech@gmail.com"
7+
}
8+
],
9+
"require": {},
10+
"autoload": {
11+
"psr-0": {
12+
"Twig_": "psr0/twig/"
13+
}
14+
}
15+
}
16+

0 commit comments

Comments
 (0)