/** * @param integer $id * @param string $country * @param bool $includeAlbums * @return Artist|null * @throws ArtistNotFoundException */ public function fetchById($id, $country = self::DEFAULT_COUNTRY, $includeAlbums = null) { $results = $this->lookup(sprintf($includeAlbums ? self::ARTIST_ALBUMS_QUERY : self::ARTIST_QUERY, (int) $id, $country)); if ($results === false) { throw new ArtistNotFoundException($id); } $artist = null; $albums = []; foreach ($results as $result) { switch ($result->wrapperType) { case self::IDENTIFIER_ARTIST: /** @var Artist $artist */ $artist = ArtistMapper::map($result); break; case self::IDENTIFIER_ALBUM: $albums[] = AlbumMapper::map($result); break; } } if ($artist) { if (!empty($albums)) { $artist->setAlbums(new Collection($albums)); } } return $artist; }
/** * @param string $name * @param string $country * @return Album[] * @throws SearchNoResultsException */ public function fetchByName($name, $country = self::DEFAULT_COUNTRY) { $results = $this->search(sprintf(self::ALBUM_SEARCH_QUERY, urlencode($name), $country)); if ($results === false) { throw new SearchNoResultsException($name); } $albums = []; foreach ($results as $result) { $albums[] = AlbumMapper::map($result); } return new SearchResults($albums); }
public function getMappers() { return [[ArtistMapper::map($this->getDataObject('artist')), 'Jacoz\\ItunesApi\\Entities\\Artist'], [AlbumMapper::map($this->getDataObject('album')), 'Jacoz\\ItunesApi\\Entities\\Album'], [TrackMapper::map($this->getDataObject('track')), 'Jacoz\\ItunesApi\\Entities\\Track']]; }