* 1.15.0 (2013-XX-XX)
+ * made ignoreStrictCheck in Template::getAttribute() works with __call() methods throwing BadMethodCallException
* added the round filter
* fixed a bug that prevented the optimizers to be enabled/disabled selectively
* fixed first and last filters for UTF-8 strings
self::$cache[$class]['methods'] = array_change_key_case(array_flip(get_class_methods($object)));
}
+ $call = false;
$lcItem = strtolower($item);
if (isset(self::$cache[$class]['methods'][$lcItem])) {
$method = (string) $item;
$method = 'is'.$item;
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
$method = (string) $item;
+ $call = true;
} else {
if ($isDefinedTest) {
return false;
// to call is not supported. If ignoreStrictCheck is true, we should return null.
try {
$ret = call_user_func_array(array($object, $method), $arguments);
- } catch (\BadMethodCallException $e) {
- if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
+ } catch (BadMethodCallException $e) {
+ if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
return null;
}
throw $e;
$this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true));
}
+ /**
+ * @dataProvider getTestsDependingOnExtensionAvailability
+ */
+ public function testGetAttributeCallExceptions($useExt = false)
+ {
+ $template = new Twig_TemplateTest(new Twig_Environment(), $useExt);
+
+ $object = new Twig_TemplateMagicMethodExceptionObject();
+
+ $this->assertEquals(null, $template->getAttribute($object, 'foo'));
+ }
+
public function getGetAttributeTests()
{
$array = array(
}
}
+class Twig_TemplateMagicMethodExceptionObject
+{
+ public function __call($method, $arguments)
+ {
+ throw new BadMethodCallException(sprintf('Unkown method %s', $method));
+ }
+}
+
class CExtDisablingNodeVisitor implements Twig_NodeVisitorInterface
{
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)