Skip to content

Instantly share code, notes, and snippets.

@predakanga
Created July 22, 2013 08:40
Show Gist options
  • Save predakanga/6052310 to your computer and use it in GitHub Desktop.
Save predakanga/6052310 to your computer and use it in GitHub Desktop.
Twig context closure support
diff --git a/lib/twig/twig/lib/Twig/Template.php b/lib/twig/twig/lib/Twig/Template.php
index a001ca0..1f3c04b 100644
--- a/lib/twig/twig/lib/Twig/Template.php
+++ b/lib/twig/twig/lib/Twig/Template.php
@@ -337,7 +337,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
{
// array
- if (Twig_TemplateInterface::METHOD_CALL !== $type) {
+ if (!is_object($object)) {
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
if ((is_array($object) && array_key_exists($arrayItem, $object))
@@ -347,7 +347,11 @@ abstract class Twig_Template implements Twig_TemplateInterface
return true;
}
- return $object[$arrayItem];
+ if(Twig_TemplateInterface::METHOD_CALL === $type) {
+ return call_user_func_array($object[$arrayItem], $arguments);
+ } else {
+ return $object[$arrayItem];
+ }
}
if (Twig_TemplateInterface::ARRAY_CALL === $type || !is_object($object)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment