Skip to content

Commit 24a13a1

Browse files
author
Greg Bowler
committed
feature: match magic paths within current directory
closes #7
1 parent 7b5080b commit 24a13a1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Path/FileMatch/MagicFileMatch.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ class MagicFileMatch extends FileMatch {
1010
];
1111

1212
public function matches(string $uriPath):bool {
13-
$uriPath = trim($uriPath, "/");
13+
$uriPath = trim($uriPath, "/") . "/";
1414
$uriPathParts = explode("/", $uriPath);
1515

1616
$filePathTrimmed = $this->getTrimmedFilePath();
1717
$uriPathParts = $this->filterDynamicPathParts($filePathTrimmed, $uriPathParts);
1818

1919
$searchDir = "";
2020
foreach($uriPathParts as $pathPart) {
21+
22+
2123
foreach(self::MAGIC_FILENAME_ARRAY as $magicFilename) {
2224
$searchFilepath = trim("$searchDir/$magicFilename", "/");
2325
if($searchFilepath === $filePathTrimmed) {

test/phpunit/Path/FileMatch/MagicFileMatchTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public function testMatches_parentDir():void {
3737
self::assertTrue($sut->matches("/something/nested"));
3838
}
3939

40+
public function testMatches_parentParentDir():void {
41+
$sut = new MagicFileMatch(
42+
"basedir/_common.php",
43+
"basedir"
44+
);
45+
self::assertTrue($sut->matches("/something/deeply/nested"));
46+
}
47+
4048
public function testMatches_ancestorDir():void {
4149
$sut = new MagicFileMatch(
4250
"basedir/something/_common.php",
@@ -52,4 +60,12 @@ public function testMatches_dynamicDir():void {
5260
);
5361
self::assertTrue($sut->matches("/something/this-is-dynamic/test"));
5462
}
63+
64+
public function testMatches_dynamicInDir():void {
65+
$sut = new MagicFileMatch(
66+
"basedir/something/@dynamic/_common.php",
67+
"basedir"
68+
);
69+
self::assertTrue($sut->matches("/something/this-is-dynamic"));
70+
}
5571
}

0 commit comments

Comments
 (0)