From 001685ba137554d37bf65eb4b476bf460f0bbc65 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 16 Nov 2010 10:51:23 +0100 Subject: [PATCH] added support for is*() methods for attributes (foo.bar now looks for foo->getBar() or foo->isBar()) --- CHANGELOG | 1 + doc/02-Twig-for-Template-Designers.markdown | 1 + lib/Twig/Template.php | 2 ++ 3 files changed, 4 insertions(+), 0 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9f2e73b..8fa845e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ Backward incompatibilities: (the old behavior is still possible by adding the "only" keyword) * Moved Exceptions to Twig_Error_* (Twig_SyntaxError/Twig_RuntimeError are now Twig_Error_Syntax/Twig_Error_Runtime) + * added support for is*() methods for attributes (foo.bar now looks for foo->getBar() or foo->isBar()) * changed all exceptions to extend Twig_Error * fixed unary expressions ({{ not(1 or 0) }}) * fixed child templates (with an extend tag) that uses one or more imports diff --git a/doc/02-Twig-for-Template-Designers.markdown b/doc/02-Twig-for-Template-Designers.markdown index 8ca677e..bf603d2 100644 --- a/doc/02-Twig-for-Template-Designers.markdown +++ b/doc/02-Twig-for-Template-Designers.markdown @@ -90,6 +90,7 @@ If a variable or attribute does not exist you will get back a `null` value > * if not, and if `foo` is an object, check that `bar` is a valid method > (even if `bar` is the constructor - use `__construct()` instead); > * if not, and if `foo` is an object, check that `getBar` is a valid method; +> * if not, and if `foo` is an object, check that `isBar` is a valid method (as of Twig 0.9.9); > * if not, return a `null` value. > >`foo['bar']` on the other hand works mostly the same with the a small diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 2e4fd2f..a1566fd 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -152,6 +152,8 @@ abstract class Twig_Template implements Twig_TemplateInterface $method = $item; } elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) { $method = 'get'.$item; + } elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) { + $method = 'is'.$item; } elseif (isset(self::$cache[$class]['methods']['__call'])) { $method = $item; } else { -- 1.7.2.5