public static function createFromResponse(\SimpleXMLElement $response) { $track = new Track(); $track->setRawResponse($response->asXML()); $trackAttributes = $response->attributes(); if (isset($trackAttributes->rank)) { $track->setNumber((int) $trackAttributes->rank); } $track->setName((string) $response->name); $track->setDuration((int) $response->duration); $track->setMbid((string) $response->mbid); $track->setUrl((string) $response->url); $track->setStreamable((int) $response->streamable); if (!empty($response->artist)) { $track->setArtist(Artist::createFromResponse($response->artist)); } $track->setPlaycount((int) $response->playcount); $track->setListeners((int) $response->listeners); $images = array(); foreach ($response->image as $image) { $imageAttributes = $image->attributes(); if (!empty($imageAttributes->size)) { $images[(string) $imageAttributes->size] = (string) $image; } } $track->setImages($images); return $track; }