File tree 4 files changed +31
-2
lines changed
4 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 2
2
namespace Gt \Routing ;
3
3
4
4
use Countable ;
5
+ use Gt \Routing \Path \FileMatch \MagicFileMatch ;
5
6
use Iterator ;
6
7
7
8
/** @implements Iterator<int, string> */
@@ -36,7 +37,8 @@ public function remove(string $path):void {
36
37
public function containsDistinctFile ():bool {
37
38
foreach ($ this ->pathList as $ path ) {
38
39
$ fileName = pathinfo ($ path , PATHINFO_FILENAME );
39
- if ($ fileName [0 ] !== "_ " ) {
40
+ if (!str_starts_with ($ fileName , "_ " )
41
+ || !in_array ($ fileName , MagicFileMatch::MAGIC_FILENAME_ARRAY )) {
40
42
return true ;
41
43
}
42
44
}
Original file line number Diff line number Diff line change @@ -73,13 +73,13 @@ protected function filterDynamicPathParts(
73
73
array $ uriPathParts
74
74
):array {
75
75
$ filePathParts = explode ("/ " , $ filePath );
76
- $ matchingSibling = in_array ($ uriPathParts , $ this ->siblingFilePathParts );
77
76
78
77
foreach ($ uriPathParts as $ i => $ uriPathPart ) {
79
78
if (!isset ($ filePathParts [$ i ])) {
80
79
break ;
81
80
}
82
81
82
+ $ matchingSibling = in_array ($ uriPathParts , $ this ->siblingFilePathParts );
83
83
$ filePathPart = $ filePathParts [$ i ];
84
84
85
85
// On the last iteration, don't convert if there's a sibling match.
Original file line number Diff line number Diff line change @@ -92,4 +92,18 @@ public function testContainsDistinctFile():void {
92
92
93
93
self ::assertTrue ($ sut ->containsDistinctFile ());
94
94
}
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
+ }
95
109
}
Original file line number Diff line number Diff line change @@ -90,4 +90,17 @@ public function testMatches_dynamicPath_siblingMatchesIndex():void {
90
90
self ::assertTrue ($ sut ->matches ("/request/dynamic-example " ));
91
91
self ::assertFalse ($ sut ->matches ("/request/secrets " ));
92
92
}
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
+ }
93
106
}
You can’t perform that action at this time.
0 commit comments