/** * @return object Returns hydrated clone of $prototype */ public function current() { $currentValue = parent::current(); $object = clone $this->prototype; $this->hydrator->hydrate($currentValue, $object); return $object; }
/** * {@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); }
/** * * @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; }
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'); }
/** * 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; }
public function save(EntityInterface $entity) { $primaryKey = $this->getPrimaryKey(); $data = $this->hydrator->extract($entity); if ($data[$primaryKey] != '' && $this->exists($data[$primaryKey])) { // update $this->db->update()->table('main_table', $this->getMainTable())->setAll($data)->where('main_table.' . $primaryKey . '=?', $data[$primaryKey])->run(); } else { // insert $this->db->insert()->into($this->getMainTable())->addAll($data)->run(); // last_insert id $data[$primaryKey] = $this->db->getLastInsertId(); $this->hydrator->hydrate($data, $entity); } return true; }
/** {@inheritdoc} */ public function hydrate(array $data, $object) { return $this->_hydrator->hydrate(array_change_key_case($data, CASE_LOWER), $object); }
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 HydrateEvent::EVENT_HYDRATE} is triggered * * @param HydrateEvent $event * @return object * @internal */ public function onHydrate(HydrateEvent $event) { $object = $this->hydrator->hydrate($event->getHydrationData(), $event->getHydratedObject()); $event->setHydratedObject($object); return $object; }
/** * 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); }
/** * {@inheritdoc} */ public function merge(ThemeInterface $existingTheme, ThemeInterface $loadedTheme) { $loadedThemeProperties = $this->themeHydrator->extract($loadedTheme); unset($loadedThemeProperties['id']); return $this->themeHydrator->hydrate($loadedThemeProperties, $existingTheme); }