Skip to content

Instantly share code, notes, and snippets.

@rufinus
Created November 19, 2012 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rufinus/4113169 to your computer and use it in GitHub Desktop.
Save rufinus/4113169 to your computer and use it in GitHub Desktop.
Seems not to be called
<?php
namespace Admin\Hydrator;
use cwdCommon\Doctrine\EntityManagerAwareInterface;
use Zend\Stdlib\Hydrator\Strategy\DefaultStrategy;
class AgencyStrategy extends DefaultStrategy implements EntityManagerAwareInterface
{
/**
* @var \Doctrine\ORM\EntityManager
*/
private $em;
public function extract($value)
{
echo 'extract - i got called';
$result = array();
foreach ($value as $instance) {
$result[] = $instance->getAgencyId();
}
return $result;
}
public function hydrate($value)
{
echo 'hydrate - i got called';
$result = $value;
if (is_array($value)) {
$result = array();
foreach ($value as $id) {
$result[] = $this->findEntity($id);
}
}
return $result;
}
private function findEntity($id)
{
return $this->getEntityManager()->find('Admin\Entity\Agency', $id);
}
public function getEntityManager()
{
return $this->em;
}
/* (non-PHPdoc)
* @see \cwdCommon\Doctrine\EntityManagerAwareInterface::setEntityManager()
*/
public function setEntityManager(\Doctrine\ORM\EntityManager $em) {
$this->em = $em;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment