Skip to content

Commit

Permalink
Merge pull request #36 from ghunti/avoid_trigger_error
Browse files Browse the repository at this point in the history
Prepare code for Twig 2.0, and avoid error triggering
  • Loading branch information
samdark committed Nov 4, 2015
2 parents 719240a + c43e002 commit 9a32546
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ETwigViewRenderer.php
Expand Up @@ -101,7 +101,7 @@ function init()

// Adding global 'void' function (usage: {{void(App.clientScript.registerScriptFile(...))}})
// (@see ETwigViewRendererVoidFunction below for details)
$this->_twig->addFunction('void', new Twig_Function_Function('ETwigViewRendererVoidFunction'));
$this->_twig->addFunction(new Twig_SimpleFunction('void', 'ETwigViewRendererVoidFunction'));

// Adding custom globals (objects or static classes)
if (!empty($this->globals)) {
Expand Down Expand Up @@ -228,24 +228,24 @@ public function getTwig()
*/
private function _addCustom($classType, $elements)
{
$classFunction = 'Twig_'.$classType.'_Function';
$classFunction = 'Twig_Simple' . $classType;

foreach ($elements as $name => $func) {
$twigElement = null;

switch ($func) {
// Just a name of function
case is_string($func):
$twigElement = new $classFunction($func);
$twigElement = new $classFunction($name, $func);
break;
// Name of function + options array
case is_array($func) && is_string($func[0]) && isset($func[1]) && is_array($func[1]):
$twigElement = new $classFunction($func[0], $func[1]);
$twigElement = new $classFunction($name, $func[0], $func[1]);
break;
}

if ($twigElement !== null) {
$this->_twig->{'add'.$classType}($name, $twigElement);
$this->_twig->{'add'.$classType}($twigElement);
} else {
throw new CException(Yii::t('yiiext',
'Incorrect options for "{classType}" [{name}]',
Expand Down

0 comments on commit 9a32546

Please sign in to comment.