diff --git a/src/Application/UI/Control.php b/src/Application/UI/Control.php index f077f9470..bfc307a33 100644 --- a/src/Application/UI/Control.php +++ b/src/Application/UI/Control.php @@ -66,8 +66,14 @@ protected function createTemplate(/*string $class = null*/): Template public function formatTemplateClass(): ?string { - $class = preg_replace('#Presenter$|Control$#', 'Template', static::class); - if ($class === static::class || !class_exists($class)) { + return $this->checkTemplateClass(preg_replace('#Control$#', '', static::class) . 'Template'); + } + + + /** @internal */ + protected function checkTemplateClass(string $class): ?string + { + if (!class_exists($class)) { return null; } elseif (!is_a($class, Template::class, true)) { trigger_error(sprintf( diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 624ea3640..84cd6fa01 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -567,11 +567,9 @@ protected function createTemplate(/*string $class = null*/): Template public function formatTemplateClass(): ?string { - $class = preg_replace('#Presenter$#', ucfirst((string) $this->action) . 'Template', static::class); - if (class_exists($class) && is_a($class, Template::class, true)) { - return $class; - } - return parent::formatTemplateClass(); + $base = preg_replace('#Presenter$#', '', static::class); + return $this->checkTemplateClass($base . ucfirst((string) $this->action) . 'Template') + ?? $this->checkTemplateClass($base . 'Template'); } diff --git a/tests/UI/Presenter.formatTemplateClass.phpt b/tests/UI/Presenter.formatTemplateClass.phpt index b60d9dda6..80388035f 100644 --- a/tests/UI/Presenter.formatTemplateClass.phpt +++ b/tests/UI/Presenter.formatTemplateClass.phpt @@ -59,7 +59,7 @@ test('with class', function () { Assert::error(function () { $presenter = new BPresenter; Assert::null($presenter->formatTemplateClass()); - }, E_USER_NOTICE, '%a% BTemplate was found but does not implement%a%'); + }, [E_USER_NOTICE, E_USER_NOTICE]); });