From 0d7c403769ae4eb70c436480ecf27d5664d951e0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 29 Sep 2010 08:08:25 +0200 Subject: [PATCH] [Form] fixed camelization problem when looking for a method (getCreated_at -> getCreatedAt) --- src/Symfony/Component/Form/Field.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/Field.php b/src/Symfony/Component/Form/Field.php index e50a57fc86..1a4a406be1 100644 --- a/src/Symfony/Component/Form/Field.php +++ b/src/Symfony/Component/Form/Field.php @@ -543,6 +543,10 @@ abstract class Field extends Configurable implements FieldInterface */ protected function readProperty($object, PropertyPath $propertyPath) { + $camelizer = function ($path) { + return preg_replace(array('/(^|_)+(.)/e', '/\.(.)/e'), array("strtoupper('\\2')", "'_'.strtoupper('\\1')"), $path); + }; + if ($propertyPath->isIndex()) { if (!$object instanceof \ArrayAccess) { throw new InvalidPropertyException(sprintf('Index "%s" cannot be read from object of type "%s" because it doesn\'t implement \ArrayAccess', $propertyPath->getCurrent(), get_class($object))); @@ -551,8 +555,8 @@ abstract class Field extends Configurable implements FieldInterface return $object[$propertyPath->getCurrent()]; } else { $reflClass = new \ReflectionClass($object); - $getter = 'get'.ucfirst($propertyPath->getCurrent()); - $isser = 'is'.ucfirst($propertyPath->getCurrent()); + $getter = 'get'.$camelizer($propertyPath->getCurrent()); + $isser = 'is'.$camelizer($propertyPath->getCurrent()); $property = $propertyPath->getCurrent(); if ($reflClass->hasMethod($getter)) { @@ -637,4 +641,4 @@ abstract class Field extends Configurable implements FieldInterface return $html; } -} \ No newline at end of file +}