Commit c84b3e0e by Alexander Makarov

Merge pull request #3767 from grachov/patch-1

Twig extensions were added twice
parents 35312c5c b8836987
...@@ -6,7 +6,7 @@ Yii Framework 2 twig extension Change Log ...@@ -6,7 +6,7 @@ Yii Framework 2 twig extension Change Log
- Bug #2925: Fixed throwing exception when accessing AR property with null value (samdark) - Bug #2925: Fixed throwing exception when accessing AR property with null value (samdark)
- Enh #1799: Added `form_begin`, `form_end` to twig extension (samdark) - Enh #1799: Added `form_begin`, `form_end` to twig extension (samdark)
- Fixed multiple adding of extensions from the config, added support for the instantiated extensions (grachov)
2.0.0-beta April 13, 2014 2.0.0-beta April 13, 2014
------------------------- -------------------------
......
...@@ -56,7 +56,7 @@ class ViewRenderer extends BaseViewRenderer ...@@ -56,7 +56,7 @@ class ViewRenderer extends BaseViewRenderer
public $filters = []; public $filters = [];
/** /**
* @var array Custom extensions. * @var array Custom extensions.
* Example: `['Twig_Extension_Sandbox', 'Twig_Extension_Text']` * Example: `['Twig_Extension_Sandbox', new \Twig_Extension_Text()]`
*/ */
public $extensions = []; public $extensions = [];
/** /**
...@@ -84,13 +84,6 @@ class ViewRenderer extends BaseViewRenderer ...@@ -84,13 +84,6 @@ class ViewRenderer extends BaseViewRenderer
'charset' => Yii::$app->charset, 'charset' => Yii::$app->charset,
], $this->options)); ], $this->options));
// Adding custom extensions
if (!empty($this->extensions)) {
foreach ($this->extensions as $extension) {
$this->twig->addExtension(new $extension());
}
}
// Adding custom globals (objects or static classes) // Adding custom globals (objects or static classes)
if (!empty($this->globals)) { if (!empty($this->globals)) {
$this->addGlobals($this->globals); $this->addGlobals($this->globals);
...@@ -198,7 +191,7 @@ class ViewRenderer extends BaseViewRenderer ...@@ -198,7 +191,7 @@ class ViewRenderer extends BaseViewRenderer
public function addExtensions($extensions) public function addExtensions($extensions)
{ {
foreach ($extensions as $extName) { foreach ($extensions as $extName) {
$this->twig->addExtension(new $extName()); $this->twig->addExtension(is_object($extName) ? $extName : new $extName());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment