/**
  * @return object Returns hydrated clone of $prototype
  */
 public function current()
 {
     $currentValue = parent::current();
     $object = clone $this->prototype;
     $this->hydrator->hydrate($currentValue, $object);
     return $object;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function hydrate(array $data, $object)
 {
     if (isset($data['parents']) && is_array($data['parents'])) {
         $data['parents'] = new ArrayCollection($data['parents']);
     }
     return $this->decoratedHydrator->hydrate($data, $object);
 }
 /**
  * Hydrate $object with the provided $data.
  *
  * @param array $data
  * @param object $object
  *
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     // Zend hydrator:
     if ($this->hydrateService instanceof HydratorInterface) {
         return $this->hydrateService->hydrate($data, $object);
     }
     // Doctrine hydrator: (parameters switched)
     return $this->hydrateService->hydrate($object, $data);
 }
Example #4
0
 function it_proxies_hydrating_and_converts_parents_to_collection_if_needed(HydratorInterface $decoratedHydrator)
 {
     $decoratedHydrator->hydrate(Argument::that(function (array $data) {
         if (!isset($data['data']) || $data['data'] !== 'data') {
             return false;
         }
         return isset($data['parents']) && $data['parents'] instanceof Collection && $data['parents']->toArray() === ['parent object'];
     }), 'object')->willReturn('hydrated object');
     $this->hydrate(['data' => 'data', 'parents' => ['parent object']], 'object')->shouldReturn('hydrated object');
 }
 /**
  * 
  * @return Contact[]
  */
 public function findAll()
 {
     $rowset = $this->gateway->select();
     $results = [];
     foreach ($rowset as $row) {
         $contact = new Contact();
         $this->hydrator->hydrate((array) $row, $contact);
         $results[] = $contact;
     }
     return $results;
 }
 /**
  * Override getItems()
  *
  * Overrides getItems() to return a collection of entities based on the
  * provided Hydrator and entity prototype, if available.
  *
  * @param int $offset
  * @param int $itemCountPerPage
  * @return array
  */
 public function getItems($offset, $itemCountPerPage)
 {
     $set = parent::getItems($offset, $itemCountPerPage);
     if (!$this->hydrator instanceof HydratorInterface) {
         return $set;
     }
     $collection = array();
     foreach ($set as $item) {
         $collection[] = $this->hydrator->hydrate($item, clone $this->entityPrototype);
     }
     return $collection;
 }
 public function delete(EntityInterface $entity)
 {
     $primaryKey = $this->getPrimaryKey();
     $data = $this->hydrator->extract($entity);
     if (isset($data[$primaryKey]) && $data[$primaryKey] > 0) {
         $this->db->delete()->from('main_table', $this->getMainTable())->where('main_table.' . $primaryKey . '=?', $data[$primaryKey])->run();
         return true;
     }
     return false;
 }
 /**
  * Iterator: get current item
  *
  * @return object
  */
 public function current()
 {
     if ($this->buffer === null) {
         $this->buffer = -2;
         // implicitly disable buffering from here on
     } elseif (is_array($this->buffer) && isset($this->buffer[$this->position])) {
         return $this->buffer[$this->position];
     }
     $data = $this->dataSource->current();
     $object = is_array($data) ? $this->hydrator->hydrate($data, clone $this->objectPrototype) : false;
     if (is_array($this->buffer)) {
         $this->buffer[$this->position] = $object;
     }
     return $object;
 }
Example #9
0
 /** {@inheritdoc} */
 public function extract($object)
 {
     return array_change_key_case($this->_hydrator->extract($object), CASE_UPPER);
 }
Example #10
0
 function it_merges_two_themes_with_each_other_without_changing_the_id(HydratorInterface $themeHydrator, ThemeInterface $existingTheme, ThemeInterface $loadedTheme)
 {
     $themeHydrator->extract($loadedTheme)->willReturn(['id' => null, 'name' => 'theme/name', 'path' => 'another/path']);
     $themeHydrator->hydrate(['name' => 'theme/name', 'path' => 'another/path'], $existingTheme)->shouldBeCalled()->willReturn($existingTheme);
     $this->merge($existingTheme, $loadedTheme)->shouldReturn($existingTheme);
 }
 /**
  * Callback to be used when {@see ExtractEvent::EVENT_EXTRACT} is triggered
  *
  * @param ExtractEvent $event
  * @return array
  * @internal
  */
 public function onExtract(ExtractEvent $event)
 {
     $data = $this->hydrator->extract($event->getExtractionObject());
     $event->mergeExtractedData($data);
     return $data;
 }
Example #12
0
 /**
  * Hydrates an object using an array of values
  *
  * @param array $data
  * @param $obj
  * @return object
  */
 public function hydrate(array $data, $obj)
 {
     return $this->hydrator->hydrate($data, $obj);
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function merge(ThemeInterface $existingTheme, ThemeInterface $loadedTheme)
 {
     $loadedThemeProperties = $this->themeHydrator->extract($loadedTheme);
     unset($loadedThemeProperties['id']);
     return $this->themeHydrator->hydrate($loadedThemeProperties, $existingTheme);
 }