From b2e4b452a43e1b82286b972960e806ffc3014deb Mon Sep 17 00:00:00 2001 From: Brandon Turner Date: Fri, 24 Sep 2010 14:18:33 -0500 Subject: [PATCH] [Form] added support for stdClass objects ReflectionClass doesn't list properties on stdClass objects (or objects cast from arrays). This allows these annoymous objects to be used as field data. --- src/Symfony/Component/Form/Field.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Symfony/Component/Form/Field.php b/src/Symfony/Component/Form/Field.php index 090c228228..e50a57fc86 100644 --- a/src/Symfony/Component/Form/Field.php +++ b/src/Symfony/Component/Form/Field.php @@ -572,6 +572,9 @@ abstract class Field extends Configurable implements FieldInterface throw new PropertyAccessDeniedException(sprintf('Property "%s" is not public in class "%s". Maybe you should create the method "get%s()" or "is%s()"?', $property, $reflClass->getName(), ucfirst($property), ucfirst($property))); } + return $object->$property; + } else if (property_exists($object, $property)) { + // needed to support \stdClass instances return $object->$property; } else { throw new InvalidPropertyException(sprintf('Neither property "%s" nor method "%s()" nor method "%s()" exists in class "%s"', $property, $getter, $isser, $reflClass->getName())); @@ -603,6 +606,9 @@ abstract class Field extends Configurable implements FieldInterface throw new PropertyAccessDeniedException(sprintf('Property "%s" is not public in class "%s". Maybe you should create the method "set%s()"?', $property, $reflClass->getName(), ucfirst($property))); } + $objectOrArray->$property = $this->getData(); + } else if (property_exists($objectOrArray, $property)) { + // needed to support \stdClass instances $objectOrArray->$property = $this->getData(); } else { throw new InvalidPropertyException(sprintf('Neither element "%s" nor method "%s()" exists in class "%s"', $property, $setter, $reflClass->getName()));