Skip to content

Commit

Permalink
Distinct files are allowed to start with underscore (#58)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
g105b authored Oct 24, 2023
1 parent 5ed50f3 commit 9304e14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Assembly.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Gt\Routing;

use Countable;
use Gt\Routing\Path\FileMatch\MagicFileMatch;
use Iterator;

/** @implements Iterator<int, string> */
Expand Down Expand Up @@ -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;
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/phpunit/AssemblyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 9304e14

Please sign in to comment.