diff --git a/src/Logic/LogicProjectNamespace.php b/src/Logic/LogicProjectNamespace.php index a6d335cf..adf79d5e 100644 --- a/src/Logic/LogicProjectNamespace.php +++ b/src/Logic/LogicProjectNamespace.php @@ -14,15 +14,26 @@ public function __toString():string { $str = str_replace("/", "\\", $this->path); $str = $this->namespacePrefix . "\\" . $str; $str = strtok($str, "."); - $str = str_replace(["-", "@"], " ", $str); $namespace = ""; foreach(explode("\\", $str) as $part) { - $part = ucwords($part); $namespace .= "\\"; - $namespace .= str_replace(" ", "", $part); + $namespace .= $this->pathPartToClassPart($part); } $namespace = trim($namespace, "\\"); $namespace .= "Page"; return $namespace; } + + private function pathPartToClassPart(string $part):string { + $dynamicPrefix = ""; + while(str_starts_with($part, "@")) { + $dynamicPrefix .= "_"; + $part = substr($part, 1); + } + + $part = str_replace("-", " ", $part); + $part = ucwords($part); + $part = str_replace(" ", "", $part); + return $dynamicPrefix . $part; + } } diff --git a/test/phpunit/Logic/LogicExecutorTest.php b/test/phpunit/Logic/LogicExecutorTest.php index f0105a49..1aac18d2 100644 --- a/test/phpunit/Logic/LogicExecutorTest.php +++ b/test/phpunit/Logic/LogicExecutorTest.php @@ -53,6 +53,32 @@ public function testInvoke_executesClassMethodFromProjectNamespace():void { self::assertSame(["$relativePath::go()"], $invoked); } + public function testLogicProjectNamespace_preservesDynamicMarkers():void { + self::assertSame( + "Example\\App\\Page\\Shop\\_Category\\_ItemPage", + (string)new LogicProjectNamespace( + "page/shop/@category/@item.php", + "Example\\App", + ), + ); + + self::assertSame( + "Example\\App\\Page\\Shop\\_Category\\ItemPage", + (string)new LogicProjectNamespace( + "page/shop/@category/item.php", + "Example\\App", + ), + ); + + self::assertSame( + "Example\\App\\Page\\Shop\\Category\\ItemPage", + (string)new LogicProjectNamespace( + "page/shop/category/item.php", + "Example\\App", + ), + ); + } + public function testInvoke_executesProjectNamespacedFunctionWhenNoClassExists():void { $relativePath = $this->createLogicFile("FunctionPage.php", "