From 134580bfd3fbf246f8211dbd01c67fa34817eee0 Mon Sep 17 00:00:00 2001 From: Simon Erkelens Date: Tue, 29 Nov 2022 11:09:18 +1300 Subject: [PATCH] Fix when the namespace contains 'Controller' Check the reflection instance type instead of instantiating the class. Instantiating throws errors for __construct with arguments --- src/Generators/AbstractTagGenerator.php | 2 +- src/Generators/ControllerTagGenerator.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Generators/AbstractTagGenerator.php b/src/Generators/AbstractTagGenerator.php index 7f6d66b..f078871 100644 --- a/src/Generators/AbstractTagGenerator.php +++ b/src/Generators/AbstractTagGenerator.php @@ -214,7 +214,7 @@ protected function generateOwnerTags() if ($reflection->isAbstract()) { return; } - if (Injector::inst()->get($this->className) instanceof Extension) { + if ($reflection instanceof Extension) { $owners = iterator_to_array($this->getOwnerClasses($className)); $owners[] = $this->className; $tagString = sprintf('\\%s $owner', implode("|\\", array_values($owners))); diff --git a/src/Generators/ControllerTagGenerator.php b/src/Generators/ControllerTagGenerator.php index 0f049ee..77ea67d 100644 --- a/src/Generators/ControllerTagGenerator.php +++ b/src/Generators/ControllerTagGenerator.php @@ -42,7 +42,12 @@ protected function generateTags() */ protected function generateControllerObjectTags() { - $pageClassname = str_replace(['_Controller', 'Controller'], '', $this->className); + $shortName = ClassInfo::shortName($this->className); + // Strip "Controller" or "_Controller" from the class short name + $shortSansController = str_replace(['_Controller', 'Controller'], '', $shortName); + // And push it back in :) + $pageClassname = str_replace($shortName, $shortSansController, $this->className); + if (class_exists($pageClassname) && $this->isContentController($this->className)) { $pageClassname = $this->getAnnotationClassName($pageClassname);