From 3e9aaf60987d2da3958da056b743ba5cfaaae18b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Queir=C3=B3s?= Date: Wed, 13 Mar 2013 00:47:03 +0000 Subject: [PATCH] Create a HydratorAwareInterface. Use the Fieldset object hydrator if its able to provide one --- library/Zend/Form/Fieldset.php | 10 ++++++- .../Hydrator/HydratorAwareInterface.php | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 library/Zend/Stdlib/Hydrator/HydratorAwareInterface.php diff --git a/library/Zend/Form/Fieldset.php b/library/Zend/Form/Fieldset.php index 5ae078158e7..58b86de777c 100644 --- a/library/Zend/Form/Fieldset.php +++ b/library/Zend/Form/Fieldset.php @@ -13,6 +13,7 @@ use Zend\Stdlib\Hydrator; use Zend\Stdlib\Hydrator\HydratorInterface; use Zend\Stdlib\PriorityQueue; +use Zend\Stdlib\Hydrator\HydratorAwareInterface; class Fieldset extends Element implements FieldsetInterface { @@ -480,6 +481,9 @@ public function setHydrator(HydratorInterface $hydrator) /** * Get the hydrator used when binding an object to the fieldset * + * If no hydrator is present and object implements HydratorAwareInterface, + * hydrator will be retrieved from the object. + * * Will lazy-load Hydrator\ArraySerializable if none is present. * * @return HydratorInterface @@ -487,7 +491,11 @@ public function setHydrator(HydratorInterface $hydrator) public function getHydrator() { if (!$this->hydrator instanceof HydratorInterface) { - $this->setHydrator(new Hydrator\ArraySerializable()); + if ($this->object instanceof HydratorAwareInterface) { + $this->setHydrator($this->object->getHydrator()); + } else { + $this->setHydrator(new Hydrator\ArraySerializable()); + } } return $this->hydrator; } diff --git a/library/Zend/Stdlib/Hydrator/HydratorAwareInterface.php b/library/Zend/Stdlib/Hydrator/HydratorAwareInterface.php new file mode 100644 index 00000000000..f2784b3bb28 --- /dev/null +++ b/library/Zend/Stdlib/Hydrator/HydratorAwareInterface.php @@ -0,0 +1,28 @@ +