Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/Twig/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,20 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ
}

$lcItem = strtolower($item);
$deunderscoreItem = str_replace('_', '', $lcItem);
$checkDecamelItem = $lcItem !== $deunderscoreItem;
if (isset(self::$cache[$class]['methods'][$lcItem])) {
$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 ($checkDecamelItem && isset(self::$cache[$class]['methods'][$deunderscoreItem])) {
$method = $deunderscoreItem;
} elseif ($checkDecamelItem && isset(self::$cache[$class]['methods']['get'.$deunderscoreItem])) {
$method = 'get'.$deunderscoreItem;
} elseif ($checkDecamelItem && isset(self::$cache[$class]['methods']['is'.$deunderscoreItem])) {
$method = 'is'.$deunderscoreItem;
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
$method = $item;
} else {
Expand Down
15 changes: 15 additions & 0 deletions test/Twig/Tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ public function getGetAttributeTests()
array(false, null, $methodAndPropObject, 'c', array(), $methodType),
array(false, null, $methodAndPropObject, 'c', array(), $arrayType),

array(true, 'camelcase', $methodAndPropObject, 'camelcase', array(), $anyType),
array(true, 'camelcase', $methodAndPropObject, 'camelcase', array(), $methodType),

array(true, 'camelcase', $methodAndPropObject, 'camelCase', array(), $anyType),
array(true, 'camelcase', $methodAndPropObject, 'camelCase', array(), $methodType),

array(true, 'camelcase', $methodAndPropObject, 'camel_case', array(), $anyType),
array(true, 'camelcase', $methodAndPropObject, 'camel_case', array(), $methodType),
array(false, null, $methodAndPropObject, 'a', array(), $arrayType),
));

// tests when input is not an array or object
Expand Down Expand Up @@ -523,6 +532,12 @@ private function getC()
{
return 'c';
}

private $camelCase = 'camelcase_prop';
public function getCamelCase()
{
return 'camelcase';
}
}

class Twig_TemplateMagicMethodObject
Expand Down