diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 048439221..bf8646b22 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -485,16 +485,21 @@ public function formatLayoutTemplateFiles(): array } [$module, $presenter] = Helpers::splitName($this->getName()); $layout = $this->layout ? $this->layout : 'layout'; - $dir = dirname($this->getReflection()->getFileName()); - $dir = is_dir("$dir/templates") ? $dir : dirname($dir); + $rc = $this->getReflection(); + $dir = dirname($rc->getFileName()); + $dir = ($newWay = is_dir("$dir/templates")) ? $dir : dirname($dir); $list = [ "$dir/templates/$presenter/@$layout.latte", "$dir/templates/$presenter.@$layout.latte", ]; do { $list[] = "$dir/templates/@$layout.latte"; - $dir = dirname($dir); + $dir = $newWay ? false : dirname($dir); } while ($dir && $module && ([$module] = Helpers::splitName($module))); + + while (($rc = $rc->getParentClass()) && $rc->getName() !== __CLASS__) { + $list[] = dirname($rc->getFileName()) . "/templates/@$layout.latte"; + } return $list; } @@ -505,11 +510,12 @@ public function formatLayoutTemplateFiles(): array public function formatTemplateFiles(): array { [, $presenter] = Helpers::splitName($this->getName()); - $dir = dirname($this->getReflection()->getFileName()); - $dir = is_dir("$dir/templates") ? $dir : dirname($dir); + $presenterDir = dirname($this->getReflection()->getFileName()); + $dir = is_dir("$presenterDir/templates") ? $presenterDir : dirname($presenterDir); return [ "$dir/templates/$presenter/$this->view.latte", "$dir/templates/$presenter.$this->view.latte", + "$presenterDir/templates/$this->view.latte", ]; } diff --git a/tests/UI/Presenter.formatLayoutTemplateFiles.phpt b/tests/UI/Presenter.formatLayoutTemplateFiles.phpt index 09b5c015a..6e1e55007 100644 --- a/tests/UI/Presenter.formatLayoutTemplateFiles.phpt +++ b/tests/UI/Presenter.formatLayoutTemplateFiles.phpt @@ -27,7 +27,7 @@ test(function () { // with subdir templates }); -test(function () { // without subdir templates +test(function () { // without subdir templates & parent presenter $presenter = new Presenter2; $presenter->setParent(null, 'Two'); @@ -35,6 +35,7 @@ test(function () { // without subdir templates __DIR__ . '/templates/Two/@layout.latte', __DIR__ . '/templates/Two.@layout.latte', __DIR__ . '/templates/@layout.latte', + __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/@layout.latte', ], $presenter->formatLayoutTemplateFiles()); }); @@ -47,13 +48,11 @@ test(function () { // with module & subdir templates __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One/@layout.latte', __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One.@layout.latte', __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/@layout.latte', - __DIR__ . '/templates/@layout.latte', - dirname(__DIR__) . '/templates/@layout.latte', ], $presenter->formatLayoutTemplateFiles()); }); -test(function () { // with module & without subdir templates +test(function () { // with module & without subdir templates & parent presenter $presenter = new Presenter2; $presenter->setParent(null, 'Module:SubModule:Two'); @@ -63,6 +62,7 @@ test(function () { // with module & without subdir templates __DIR__ . '/templates/@layout.latte', dirname(__DIR__) . '/templates/@layout.latte', dirname(dirname(__DIR__)) . '/templates/@layout.latte', + __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/@layout.latte', ], $presenter->formatLayoutTemplateFiles()); }); diff --git a/tests/UI/Presenter.formatTemplateFiles.phpt b/tests/UI/Presenter.formatTemplateFiles.phpt index 19770561e..2394e1cb9 100644 --- a/tests/UI/Presenter.formatTemplateFiles.phpt +++ b/tests/UI/Presenter.formatTemplateFiles.phpt @@ -22,6 +22,7 @@ test(function () { // with subdir templates Assert::same([ __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One/view.latte', __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One.view.latte', + __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/view.latte', ], $presenter->formatTemplateFiles()); }); @@ -34,6 +35,7 @@ test(function () { // without subdir templates Assert::same([ __DIR__ . '/templates/Two/view.latte', __DIR__ . '/templates/Two.view.latte', + __DIR__ . DIRECTORY_SEPARATOR . 'two/templates/view.latte', ], $presenter->formatTemplateFiles()); }); @@ -46,6 +48,7 @@ test(function () { // with module & subdir templates Assert::same([ __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One/view.latte', __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/One.view.latte', + __DIR__ . DIRECTORY_SEPARATOR . 'one/templates/view.latte', ], $presenter->formatTemplateFiles()); }); @@ -58,5 +61,6 @@ test(function () { // with module & without subdir templates Assert::same([ __DIR__ . '/templates/Two/view.latte', __DIR__ . '/templates/Two.view.latte', + __DIR__ . DIRECTORY_SEPARATOR . 'two/templates/view.latte', ], $presenter->formatTemplateFiles()); });