Beispiel #1
0
 public function __construct()
 {
     parent::__construct('add');
     $hydrator = new AggregateHydrator();
     $hydrator->add(new PostHydrator());
     $hydrator->add(new CategoryHydrator());
     $this->setHydrator($hydrator);
     $title = new Element\Text('title');
     $title->setLabel('Title');
     $title->setAttribute('class', 'form-control');
     $slug = new Element\Text('slug');
     $slug->setLabel('Slug');
     $slug->setAttribute('class', 'form-control');
     $content = new Element\Textarea('content');
     $content->setLabel('Content');
     $content->setAttribute('class', 'form-control');
     $category = new Element\Select('category_id');
     $category->setLabel('Category');
     $category->setAttribute('class', 'form-control');
     $category->setValueOptions(array(1 => 'WIN', 2 => 'BUILD', 3 => 'SEND', 4 => 'GENERAL'));
     $submit = new Element\Submit('submit');
     $submit->setValue('Add News');
     $submit->setAttribute('class', 'btn btn-primary');
     $this->add($title);
     $this->add($slug);
     $this->add($content);
     $this->add($category);
     $this->add($submit);
 }
 /**
  * Hydrate $object with the provided $data.
  *
  * @param  array $data
  * @param  object $object
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     if (!isset($data['album'])) {
         return $object;
     }
     $hydrators = new AggregateHydrator();
     $hydrators->add(new AlbumHydrator());
     $hydrators->add(new ImageCollectionAwareHydrator());
     $object->setAlbum($hydrators->hydrate($data['album'], new Album()));
     return $object;
 }
 /**
  * Hydrate $object with the provided $data.
  *
  * @param  array $data
  * @param  object $object
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     if (!isset($data['owner'])) {
         return $object;
     }
     $hydrators = new AggregateHydrator();
     $hydrators->add(new UserHydrator());
     $hydrators->add(new ImageCollectionAwareHydrator());
     $object->setOwner($hydrators->hydrate($data['owner'], new User()));
     return $object;
 }
 /**
  * @param array $data
  * @param ArtistCollection $object
  * @return ArtistCollection
  */
 public function hydrate(array $data, $object)
 {
     if (!isset($data['artists'])) {
         return $object;
     }
     foreach ($data['artists'] as $artist) {
         $hydrators = new AggregateHydrator();
         $hydrators->add(new ArtistHydrator());
         $hydrators->add(new ImageCollectionAwareHydrator());
         $object->add($hydrators->hydrate($artist, new Artist()));
     }
     return $object;
 }
 /**
  * Hydrate $object with the provided $data.
  *
  * @param  array $data
  * @param  object $object
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     if (!isset($data['track'])) {
         return $object;
     }
     $hydrators = new AggregateHydrator();
     $hydrators->add(new TrackHydrator());
     $hydrators->add(new AlbumAwareHydrator());
     $hydrators->add(new ArtistCollectionAwareHydrator());
     $hydrators->add(new ImageCollectionAwareHydrator());
     $object->setTrack($hydrators->hydrate($data['track'], new Track()));
     return $object;
 }
 public function testHydrationDoesntHappenWhenNoKeysAreFound()
 {
     $data = ['baz' => 'LONELY BAZ'];
     $aggregateHydrator = new AggregateHydrator();
     $aggregateHydrator->add(new ClassMethods());
     $aggregateHydrator->add(new OneToOneHydrator('foo_', 'setFoo', new Foo()));
     $aggregateHydrator->add(new OneToOneHydrator('bar_', 'setBar', new Bar()));
     $dummy = $aggregateHydrator->hydrate($data, new Dummy());
     $this->assertInstanceOf('SamTest\\DummyEntity\\Dummy', $dummy);
     $this->assertEquals('LONELY BAZ', $dummy->getBaz());
     $this->assertNull($dummy->getFoo());
     $this->assertNull($dummy->getBar());
 }
 /**
  * @param $postId int
  *
  * @return Post|null
  */
 public function findById($postId)
 {
     $sql = new \Zend\Db\Sql\Sql($this->adapter);
     $select = $sql->select();
     $select->columns(array('id', 'title', 'slug', 'content', 'created'))->from(array('p' => 'news'))->join(array('c' => 'category'), 'c.id = p.category_id', array('category_id' => 'id', 'name', 'category_slug' => 'slug'), $select::JOIN_INNER)->where(array('p.id' => $postId));
     $statement = $sql->prepareStatementForSqlObject($select);
     $results = $statement->execute();
     $hydrator = new AggregateHydrator();
     $hydrator->add(new PostHydrator());
     $hydrator->add(new CategoryHydrator());
     $resultSet = new HydratingResultSet($hydrator, new Post());
     $resultSet->initialize($results);
     return $resultSet->count() > 0 ? $resultSet->current() : null;
 }
 /**
  * @param array $data
  * @param Pagination $object
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     if (!isset($data['items'])) {
         return $object;
     }
     $albumCollection = new AlbumCollection();
     foreach ($data['items'] as $album) {
         $hydrators = new AggregateHydrator();
         $hydrators->add(new AlbumHydrator());
         $hydrators->add(new ImageCollectionAwareHydrator());
         $albumCollection->add($hydrators->hydrate($album, new Album()));
     }
     $object->setItems($albumCollection);
     return $object;
 }
 /**
  * @param array $data
  * @param TrackCollection $object
  * @return TrackCollection
  */
 public function hydrate(array $data, $object)
 {
     if (!isset($data['tracks'])) {
         return $object;
     }
     foreach ($data['tracks'] as $track) {
         $hydrators = new AggregateHydrator();
         $hydrators->add(new TrackHydrator());
         $hydrators->add(new AlbumAwareHydrator());
         $hydrators->add(new ArtistCollectionAwareHydrator());
         $hydrators->add(new ImageCollectionAwareHydrator());
         $object->add($hydrators->hydrate($track, new Track()));
     }
     return $object;
 }
 /**
  * @param array $data
  * @param AlbumCollection $object
  * @return AlbumCollection
  */
 public function hydrate(array $data, $object)
 {
     if (!isset($data['albums'])) {
         return $object;
     }
     foreach ($data['albums'] as $album) {
         $hydrators = new AggregateHydrator();
         $hydrators->add(new AlbumHydrator());
         $hydrators->add(new ArtistCollectionAwareHydrator());
         $hydrators->add(new ImageCollectionAwareHydrator());
         $hydrators->add(new PaginatedTrackCollectionAwareHydrator());
         $object->add($hydrators->hydrate($album, new Album()));
     }
     return $object;
 }
 /**
  * @param array $data
  * @param Pagination $object
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     if (!isset($data['items'])) {
         return $object;
     }
     $playlistCollection = new PlaylistCollection();
     foreach ($data['items'] as $playlist) {
         $hydrators = new AggregateHydrator();
         $hydrators->add(new PlaylistHydrator());
         $hydrators->add(new OwnerAwareHydrator());
         $hydrators->add(new TracksAwareHydrator());
         $playlistCollection->add($hydrators->hydrate($playlist, new Playlist()));
     }
     $object->setItems($playlistCollection);
     return $object;
 }
 /**
  * Verifies that stopping propagation within a listener in the hydrator allows modifying how the
  * hydrator behaves
  */
 public function testStoppedPropagationInHydration()
 {
     $object = new ArrayObject();
     $swappedObject = new stdClass();
     $callback = function (HydrateEvent $event) use($swappedObject) {
         $event->setHydratedObject($swappedObject);
         $event->stopPropagation();
     };
     $this->hydrator->add(new ArraySerializable());
     $this->hydrator->getEventManager()->attach(HydrateEvent::EVENT_HYDRATE, $callback, 1000);
     $this->assertSame($swappedObject, $this->hydrator->hydrate(array('president' => 'Zaphod'), $object));
 }
 /**
  * @param array $data
  * @param object $object
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     if (!isset($data['tracks'])) {
         return $object;
     }
     $paginatedTrackCollection = new Pagination($data['tracks']);
     $playlistTrackCollection = new PlaylistTrackCollection();
     foreach ($paginatedTrackCollection->getItems() as $track) {
         $hydrators = new AggregateHydrator();
         $hydrators->add(new TrackAwareHydrator());
         $playlistTrackCollection->add($hydrators->hydrate($track, new PlaylistTrack()));
     }
     $paginatedTrackCollection->setItems($playlistTrackCollection);
     $object->setTracks($paginatedTrackCollection);
     return $object;
 }
 /**
  * @covers \Zend\Stdlib\Hydrator\Aggregate\AggregateHydrator::add
  */
 public function testAdd()
 {
     $attached = $this->getMock('Zend\\Stdlib\\Hydrator\\HydratorInterface');
     $this->eventManager->expects($this->once())->method('attachAggregate')->with($this->isInstanceOf('Zend\\Stdlib\\Hydrator\\Aggregate\\HydratorListener'), 123);
     $this->hydrator->add($attached, 123);
 }
Beispiel #15
0
 /**
  * @param string $id
  * @return Entity\PlaylistPagination
  */
 public function getUserPlaylists($id)
 {
     $request = $this->guzzleClient->createRequest('GET', sprintf('/v1/users/%s/playlists', $id));
     $response = $this->sendRequest($request)->json();
     $hydrators = new AggregateHydrator();
     $hydrators->add(new Hydrator\PaginationHydrator());
     $hydrators->add(new Hydrator\PaginatedPlaylistCollectionHydrator());
     return $hydrators->hydrate($response, new Entity\PlaylistPagination());
 }