From 9304e14076b6ce06b6db88f6958549ce6efdc8de Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Tue, 24 Oct 2023 18:57:57 +0100 Subject: [PATCH] Distinct files are allowed to start with underscore (#58) * feature: deeper dynamic pages closes #4 * build: upgrade build packages for downstream deps * tweak: phpstorm analysis * test: isolate issue #57 * feature: allow underscore files closes #57 --- src/Assembly.php | 4 +++- test/phpunit/AssemblyTest.php | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Assembly.php b/src/Assembly.php index 3e3c5ac..d4a5fad 100644 --- a/src/Assembly.php +++ b/src/Assembly.php @@ -2,6 +2,7 @@ namespace Gt\Routing; use Countable; +use Gt\Routing\Path\FileMatch\MagicFileMatch; use Iterator; /** @implements Iterator */ @@ -36,7 +37,8 @@ public function remove(string $path):void { public function containsDistinctFile():bool { foreach($this->pathList as $path) { $fileName = pathinfo($path, PATHINFO_FILENAME); - if($fileName[0] !== "_") { + if(!str_starts_with($fileName, "_") + || !in_array($fileName, MagicFileMatch::MAGIC_FILENAME_ARRAY)) { return true; } } diff --git a/test/phpunit/AssemblyTest.php b/test/phpunit/AssemblyTest.php index cbebc4d..288dcc7 100644 --- a/test/phpunit/AssemblyTest.php +++ b/test/phpunit/AssemblyTest.php @@ -92,4 +92,18 @@ public function testContainsDistinctFile():void { self::assertTrue($sut->containsDistinctFile()); } + + public function testContainsDistinctFile_magicFilename():void { + $pathList = [ + "/var/www/_header.html", + "/var/www/_new.html", + "/var/www/_footer.html", + ]; + $sut = new Assembly(); + foreach($pathList as $path) { + $sut->add($path); + } + + self::assertTrue($sut->containsDistinctFile()); + } }