public static function createFromResponse(\SimpleXMLElement $response) { $album = new Album(); $album->setRawResponse($response); $album->setId((int) $response->id); $album->setName((string) $response->name); $artisNodeCount = count($response->artist->children()); if (!empty($artisNodeCount)) { $artist = Artist::createFromResponse($response->artist); } else { $artist = new Artist(); $artist->setName((string) $response->artist); } $album->setArtist($artist); $album->setUrl((string) $response->url); $images = array(); foreach ($response->image as $image) { $images[] = (string) $image; } $album->setImages($images); $album->setStreamable((bool) $response->streamable); $album->setMbid((string) $response->mbid); $album->setReleaseDate((string) $response->releasedate); $album->setListeners((int) $response->listeners); $album->setPlayCount((int) $response->playcount); $album->setStreamable((int) $response->streamable); $topTags = array(); foreach ($response->toptags as $topTag) { $topTags[] = $topTag; } $album->setTopTags($topTags); $tracks = array(); if (!empty($response->tracks->track)) { foreach ($response->tracks->track as $track) { $tracks[] = Track::createFromResponse($track); } $album->setTracks($tracks); } return $album; }