Август 2008, 21 @ 06:14 Мастерю PHP ZendFramework
ZendFramework - говно.
P.S. Zend_Service_Audioscrobbler тоже говно на кучу строк.
Мой шикарнейший вариант, короткий, как писька у японца:
<?
class Service_LastFM {
////////////////////////////////////////////////////////////////////////////////
function __call($method, $params){
list($type, $that) = explode('_', strtolower($method), 2);
$url .= 'http://ws.audioscrobbler.com/1.0/';
$url .= $type.'/'.urlencode($params[0]).'/';
$url .= (is_string($params[1]) ? urlencode($params[1]).'/' : '');
$url .= $that.'.xml';
$url .= (is_array($query = end($params)) ? '?'.http_build_query($query) : '');
$status = reset(get_headers($url));
$status = trim(strstr($status, ' '));
unset($this->error);
if ($status == '200 OK')
return simplexml_load_file($url);
$this->error = $status;
}
////////////////////////////////////////////////////////////////////////////////
}
?>
Пользовать так:
<?
$lastfm = new Service_LastFM;
print_r($lastfm->user_profile('RJ'));
print_r($lastfm->user_artistTags('RJ', array('artist' => 'Metallica')));
print_r($lastfm->track_artistTags('Metallica', 'Enter Sandman'));
print_r($lastfm->album_info('Metallica', 'Ride the Lightning'));
?>
И всяко разно.
В случае успеха класс вернёт SimpleXML обьект. В противном случае в переменной $lastfm->error будет хидер с ощибкой (400 Malformed API Call (пример этой ошибки), 404 Not Found и т.д.).