Skip to content

Commit f9acf4e

Browse files
committed
Merge branch 'master' of github.com:/PhpGt/Routing
2 parents 79ac35a + 9304e14 commit f9acf4e

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/Assembly.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Gt\Routing;
33

44
use Countable;
5+
use Gt\Routing\Path\FileMatch\MagicFileMatch;
56
use Iterator;
67

78
/** @implements Iterator<int, string> */
@@ -36,7 +37,8 @@ public function remove(string $path):void {
3637
public function containsDistinctFile():bool {
3738
foreach($this->pathList as $path) {
3839
$fileName = pathinfo($path, PATHINFO_FILENAME);
39-
if($fileName[0] !== "_") {
40+
if(!str_starts_with($fileName, "_")
41+
|| !in_array($fileName, MagicFileMatch::MAGIC_FILENAME_ARRAY)) {
4042
return true;
4143
}
4244
}

src/Path/FileMatch/FileMatch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ protected function filterDynamicPathParts(
7373
array $uriPathParts
7474
):array {
7575
$filePathParts = explode("/", $filePath);
76-
$matchingSibling = in_array($uriPathParts, $this->siblingFilePathParts);
7776

7877
foreach($uriPathParts as $i => $uriPathPart) {
7978
if(!isset($filePathParts[$i])) {
8079
break;
8180
}
8281

82+
$matchingSibling = in_array($uriPathParts, $this->siblingFilePathParts);
8383
$filePathPart = $filePathParts[$i];
8484

8585
// On the last iteration, don't convert if there's a sibling match.

test/phpunit/AssemblyTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,18 @@ public function testContainsDistinctFile():void {
9292

9393
self::assertTrue($sut->containsDistinctFile());
9494
}
95+
96+
public function testContainsDistinctFile_magicFilename():void {
97+
$pathList = [
98+
"/var/www/_header.html",
99+
"/var/www/_new.html",
100+
"/var/www/_footer.html",
101+
];
102+
$sut = new Assembly();
103+
foreach($pathList as $path) {
104+
$sut->add($path);
105+
}
106+
107+
self::assertTrue($sut->containsDistinctFile());
108+
}
95109
}

test/phpunit/Path/FileMatch/BasicFileMatchTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,17 @@ public function testMatches_dynamicPath_siblingMatchesIndex():void {
9090
self::assertTrue($sut->matches("/request/dynamic-example"));
9191
self::assertFalse($sut->matches("/request/secrets"));
9292
}
93+
94+
public function testMatches_nestedDynamicPath_siblingMatchesIndex():void {
95+
$sut = new BasicFileMatch(
96+
"page/request/@share-id/@request-id.html",
97+
"page",
98+
[
99+
"page/request/@share-id/index.html",
100+
"page/request/@share-id/secrets.html",
101+
]
102+
);
103+
self::assertTrue($sut->matches("/request/share123/dynamic-example"));
104+
self::assertFalse($sut->matches("/request/share123/secrets"));
105+
}
93106
}

0 commit comments

Comments
 (0)