Skip to content

Commit

Permalink
merged branch ShadowPrince/master (PR twigphp#1042)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the master branch (closes twigphp#1042).

Discussion
----------

Registration a Twig_SimpleFunction after extensions initialized throw not LogicException, but Fatal Error

Registration a Twig_SimpleFunction after extensions initialized throw not LogicException, but Fatal Error:

$environment->addFunction(new Twig_SimpleFunction(...))
after 
$environment->render(...)
throws Fatal Error: 
object of Twig_SimpleFunction could not be converted to string

Commits
-------

92e97b9 Registration a Twig_SimpleFunction after extensions initialized throw not LogicException, but Fatal Error
  • Loading branch information
fabpot committed Apr 1, 2013
2 parents e8991cc + 92e97b9 commit 296bae9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/Twig/Environment.php
Expand Up @@ -756,10 +756,6 @@ public function getNodeVisitors()
*/ */
public function addFilter($name, $filter = null) public function addFilter($name, $filter = null)
{ {
if ($this->extensionInitialized) {
throw new LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $name));
}

if (!$name instanceof Twig_SimpleFilter && !($filter instanceof Twig_SimpleFilter || $filter instanceof Twig_FilterInterface)) { if (!$name instanceof Twig_SimpleFilter && !($filter instanceof Twig_SimpleFilter || $filter instanceof Twig_FilterInterface)) {
throw new LogicException('A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter'); throw new LogicException('A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter');
} }
Expand All @@ -768,7 +764,11 @@ public function addFilter($name, $filter = null)
$filter = $name; $filter = $name;
$name = $filter->getName(); $name = $filter->getName();
} }


if ($this->extensionInitialized) {
throw new LogicException(sprintf('Unable to add filter "%s" as extensions have already been initialized.', $name));
}

$this->staging->addFilter($name, $filter); $this->staging->addFilter($name, $filter);
} }


Expand Down Expand Up @@ -845,10 +845,6 @@ public function getFilters()
*/ */
public function addTest($name, $test = null) public function addTest($name, $test = null)
{ {
if ($this->extensionInitialized) {
throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name));
}

if (!$name instanceof Twig_SimpleTest && !($test instanceof Twig_SimpleTest || $test instanceof Twig_TestInterface)) { if (!$name instanceof Twig_SimpleTest && !($test instanceof Twig_SimpleTest || $test instanceof Twig_TestInterface)) {
throw new LogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest'); throw new LogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest');
} }
Expand All @@ -857,6 +853,10 @@ public function addTest($name, $test = null)
$test = $name; $test = $name;
$name = $test->getName(); $name = $test->getName();
} }

if ($this->extensionInitialized) {
throw new LogicException(sprintf('Unable to add test "%s" as extensions have already been initialized.', $name));
}


$this->staging->addTest($name, $test); $this->staging->addTest($name, $test);
} }
Expand Down Expand Up @@ -903,10 +903,6 @@ public function getTest($name)
*/ */
public function addFunction($name, $function = null) public function addFunction($name, $function = null)
{ {
if ($this->extensionInitialized) {
throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name));
}

if (!$name instanceof Twig_SimpleFunction && !($function instanceof Twig_SimpleFunction || $function instanceof Twig_FunctionInterface)) { if (!$name instanceof Twig_SimpleFunction && !($function instanceof Twig_SimpleFunction || $function instanceof Twig_FunctionInterface)) {
throw new LogicException('A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction'); throw new LogicException('A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction');
} }
Expand All @@ -915,7 +911,11 @@ public function addFunction($name, $function = null)
$function = $name; $function = $name;
$name = $function->getName(); $name = $function->getName();
} }


if ($this->extensionInitialized) {
throw new LogicException(sprintf('Unable to add function "%s" as extensions have already been initialized.', $name));
}

$this->staging->addFunction($name, $function); $this->staging->addFunction($name, $function);
} }


Expand Down

0 comments on commit 296bae9

Please sign in to comment.