From 912132d250598c4db64bf6f421f6b9e1123ca32d Mon Sep 17 00:00:00 2001 From: "Bruno O. Notario" Date: Sun, 24 Mar 2024 03:21:36 -0300 Subject: [PATCH] Bugfix injection of ended Factory class name --- system/engine/registry.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/system/engine/registry.php b/system/engine/registry.php index f226aa4..62e843b 100644 --- a/system/engine/registry.php +++ b/system/engine/registry.php @@ -396,7 +396,12 @@ final class Registry { if (preg_match($pattern, $declaringClass, $matches)) { $classFactoryName = $matches[1]; - if (substr($classFactoryName, -(strlen(self::FACTORY_WORD_KEY))) === self::FACTORY_WORD_KEY) { + $classAttr = self::checkPreference($classFactoryName); + + if (class_exists($classAttr)) { + $argsToInject[$param->getPosition()] = $this->injectionClass($classFactoryName); + continue; + } elseif (substr($classFactoryName, -(strlen(self::FACTORY_WORD_KEY))) === self::FACTORY_WORD_KEY && substr($classFactoryName, - (strlen(self::FACTORY_WORD_KEY)+1)) != "\\".self::FACTORY_WORD_KEY) { $factoredRefClass = substr($classFactoryName, 0, -(strlen(self::FACTORY_WORD_KEY))); if (!class_exists($classFactoryName) && $classFactoryName != self::FACTORY_CLASS) { @@ -429,7 +434,7 @@ final class Registry { if (class_exists($classAttr)) { $argsToInject[$param->getPosition()] = $this->injectionClass($injectionClass); continue; - } elseif (substr($injectionClass, -(strlen(self::FACTORY_WORD_KEY))) === self::FACTORY_WORD_KEY) { + } elseif (substr($injectionClass, -(strlen(self::FACTORY_WORD_KEY))) === self::FACTORY_WORD_KEY && substr($injectionClass, - (strlen(self::FACTORY_WORD_KEY) + 1)) != "\\" . self::FACTORY_WORD_KEY) { // Create a factored instance $factoredRefClass = substr($injectionClass, 0, -(strlen(self::FACTORY_WORD_KEY))); $argsToInject[$param->getPosition()] = ($this->getInstance($injectionClass, [], true)) ?: self::setAutoInstance($this->create(self::FACTORY_CLASS, [$factoredRefClass]), $injectionClass);