Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Create a HydratorAwareInterface. Use the Fieldset object hydrator if …
Browse files Browse the repository at this point in the history
…its able to provide one
  • Loading branch information
ghunti committed Mar 13, 2013
1 parent 3659323 commit 3e9aaf6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
10 changes: 9 additions & 1 deletion library/Zend/Form/Fieldset.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -480,14 +481,21 @@ 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
*/
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;
}
Expand Down
28 changes: 28 additions & 0 deletions library/Zend/Stdlib/Hydrator/HydratorAwareInterface.php
@@ -0,0 +1,28 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Stdlib\Hydrator;

interface HydratorAwareInterface
{
/**
* Set hydrator
*
* @param HydratorInterface $hydrator
* @return HydratorAwareInterface
*/
public function setHydrator(HydratorInterface $hydrator);

/**
* Retrieve hydrator
*
* @return HydratorInterface
*/
public function getHydrator();
}

0 comments on commit 3e9aaf6

Please sign in to comment.