Beispiel #1
0
 public function testEntityCanBeHydrated()
 {
     // http://framework.zend.com/manual/current/en/modules/zend.stdlib.hydrator.html
     $data = ['name' => 'Customer Location 1', 'address' => '5 Hedderwick Hill, West Barns, Dunbar, E. Lothian, EH42 1XF', 'latitude' => 52.855864, 'longitude' => -1.457062];
     $hydrator = new Hydrator\ArraySerializable();
     $entity = $hydrator->hydrate($data, new Entity\Location());
     self::assertInstanceOf(Entity\Location::class, $entity);
 }
 /**
  * Get a hydrator to bind CustomField objects to the database
  *
  * Unlike other tables, the hydrator cannot be provided by the CustomFields
  * table class due to tricky dependencies. Use this method to get a suitable
  * hydrator.
  *
  * @return \Zend\Hydrator\ArraySerializable
  */
 public function getHydrator()
 {
     if (!$this->_hydrator) {
         $columns = $this->getColumnMap();
         $this->_hydrator = new \Zend\Hydrator\ArraySerializable();
         $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array_flip($columns)));
         $dateStrategy = new \Zend\Hydrator\Strategy\DateTimeFormatterStrategy('Y-m-d');
         foreach ($this->getFields() as $name => $type) {
             if ($type == 'date') {
                 $this->_hydrator->addStrategy($name, $dateStrategy);
                 $this->_hydrator->addStrategy($columns[$name], $dateStrategy);
             }
         }
     }
     return $this->_hydrator;
 }