From: Arnaud Le Blanc Date: Sun, 15 Aug 2010 20:03:36 +0000 (+0200) Subject: Fix for bug #101 : make magic calls case-sensitive in subscript expressions (closes... X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=839f16145e9c29f8fd52fed81af26fd1e52ee331;p=web%2Fkonrad%2Ftwig.git Fix for bug #101 : make magic calls case-sensitive in subscript expressions (closes #101) --- diff --git a/CHANGELOG b/CHANGELOG index 589d2e7..3018b7e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ Backward incompatibilities: * the odd and even filters are now tests: {{ foo|odd }} must now be written {{ foo is odd }} + * fixed subscript expressions when calling __call() (methods now keep the case) * added a "trans" filter * added "test" feature (accessible via the "is" operator) * removed the debug tag (should be done in an extension) diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 7643758..b4b4b92 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -138,10 +138,10 @@ abstract class Twig_Template implements Twig_TemplateInterface } // object method - $item = strtolower($item); - if (isset(self::$cache[$class]['methods'][$item])) { + $lcItem = strtolower($item); + if (isset(self::$cache[$class]['methods'][$lcItem])) { $method = $item; - } elseif (isset(self::$cache[$class]['methods']['get'.$item])) { + } elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) { $method = 'get'.$item; } elseif (isset(self::$cache[$class]['methods']['__call'])) { $method = $item; diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 92b6f6f..4e9f4a4 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -41,14 +41,17 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase // METHOD array('bar', $object, 'bar', array(), $methodType), array('bar', $object, 'getBar', array(), $methodType), + array('bar', $object, 'getbar', array(), $methodType), array('foobar', $object, 'foobar', array(), $methodType), array('babar', $object, 'babar', array(), $methodType), array('babarStatic', $object, 'babarStatic', array(), $methodType), array('__call_baz', $objectMagic, 'baz', array(), $methodType), + array('__call_Baz', $objectMagic, 'Baz', array(), $methodType), // ANY array('foo', $object, 'foo', array(), $anyType), array('foo', $objectMagic, 'foo', array(), $anyType), + array('Foo', $objectMagic, 'Foo', array(), $anyType), array(null, $object, 'null', array(), $anyType), ); @@ -134,7 +137,7 @@ class Twig_TemplateObjectArrayAccess implements ArrayAccess class Twig_TemplateObjectMagic { - public $attributes = array('foo' => 'foo'); + public $attributes = array('foo' => 'foo', 'Foo' => 'Foo'); public function __isset($name) {