diff --git a/system/engine/registry.php b/system/engine/registry.php index 0826fc0..ef58d9d 100644 --- a/system/engine/registry.php +++ b/system/engine/registry.php @@ -336,6 +336,9 @@ final class Registry { $originalClass = $class; $class = self::checkPreference($class); $originalClass = $originalClass == $class ? null : $originalClass; + + if($class === get_class($this)) return $this; + $refClass = new ReflectionClass($class); try { @@ -344,9 +347,9 @@ final class Registry { if (!$refClass->getConstructor() && !$argsToInject) { if ($refClass->hasMethod('getInstance') && $refClass->getMethod('getInstance')->isStatic()) { - return $refClass->getMethod('getInstance')->invoke(null); + return self::setAutoInstance($refClass->getMethod('getInstance')->invoke(null), ($originalClass ?: $class)); } - return $refClass->newInstanceWithoutConstructor(); + return self::setAutoInstance($refClass->newInstanceWithoutConstructor(), ($originalClass ?: $class)); } } catch (\Exception $th) { diff --git a/system/templateEngines/Twig/Api/Extension/TranslateInterface.php b/system/templateEngines/Twig/Api/Extension/TranslateInterface.php index c782b15..a90d42c 100644 --- a/system/templateEngines/Twig/Api/Extension/TranslateInterface.php +++ b/system/templateEngines/Twig/Api/Extension/TranslateInterface.php @@ -12,6 +12,7 @@ namespace Phacil\Framework\templateEngines\Twig\Api\Extension; * Twig translate extension interface * * @package Phacil\Framework\templateEngines\Twig\Api\Extension + * @since 2.0.0 */ interface TranslateInterface { diff --git a/system/templateEngines/Twig/Extension/Legacy/Translate.php b/system/templateEngines/Twig/Extension/Legacy/Translate.php index 833bc82..9617d3e 100644 --- a/system/templateEngines/Twig/Extension/Legacy/Translate.php +++ b/system/templateEngines/Twig/Extension/Legacy/Translate.php @@ -13,6 +13,15 @@ use Phacil\Framework\templateEngines\Twig\Extension\Legacy\TokenParser; class Translate extends \Twig_Extension implements TranslateInterface { + /** + * + * @var \Phacil\Framework\templateEngines\Twig\Extension\Legacy\TokenParser + */ + private $tokenParser; + + public function __construct(TokenParser $tokenParser){ + $this->tokenParser = $tokenParser; + } /** * {@inheritdoc} @@ -20,7 +29,7 @@ class Translate extends \Twig_Extension implements TranslateInterface public function getTokenParsers() { return array( - new TokenParser(), + $this->tokenParser, ); } diff --git a/system/templateEngines/Twig/Extension/Translate.php b/system/templateEngines/Twig/Extension/Translate.php index 4feda14..ca9b977 100644 --- a/system/templateEngines/Twig/Extension/Translate.php +++ b/system/templateEngines/Twig/Extension/Translate.php @@ -13,6 +13,16 @@ use Phacil\Framework\templateEngines\Twig\Extension\TokenParser; class Translate extends \Twig\Extension\AbstractExtension implements TranslateInterface { + /** + * + * @var \Phacil\Framework\templateEngines\Twig\Extension\Legacy\TokenParser + */ + private $tokenParser; + + public function __construct(TokenParser $tokenParser) + { + $this->tokenParser = $tokenParser; + } /** * {@inheritdoc} @@ -20,7 +30,7 @@ class Translate extends \Twig\Extension\AbstractExtension implements TranslateIn public function getTokenParsers() { return array( - new TokenParser(), + $this->tokenParser, ); }