Skip to content

Instantly share code, notes, and snippets.

@rufinus
Last active December 17, 2015 08:48
Show Gist options
  • Save rufinus/5582295 to your computer and use it in GitHub Desktop.
Save rufinus/5582295 to your computer and use it in GitHub Desktop.
$hydra = new DoctrineHydrator($sm->get('Doctrine\ORM\EntityManager', false));
$hydra->addStrategy('date_start', new \cwdCommon\Doctrine\Strategy\DateTime());
$hydra->addStrategy('date_end', new \cwdCommon\Doctrine\Strategy\DateTime());
$this->setHydrator($hydra);
$this->setObject(new \Application\Entity\Event());
$this->add(
array(
'name' => 'date_start',
'options' => array(
'label' => 'Date'
),
'attributes' => array(
'id' => 'date-from-raw'
)
)
);
$this->add(
array(
'name' => 'date_end',
'options' => array(
'label' => 'Date'
),
'attributes' => array(
'id' => 'date-to-raw'
)
)
);
<?php
namespace cwdCommon\Doctrine\Strategy;
use Zend\Stdlib\Hydrator\Strategy\StrategyInterface;
class DateTime implements StrategyInterface
{
/**
* Converts the given value so that it can be extracted by the hydrator.
*
* @param mixed $value The original value.
* @return mixed Returns the value that should be extracted.
*/
public function extract($value)
{
return 'extract';
}
/**
* Converts the given value so that it can be hydrated by the hydrator.
*
* @param mixed $value The original value.
* @return mixed Returns the value that should be hydrated.
*/
public function hydrate($value)
{
return 'hydrate';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment