本文整理汇总了PHP中Tag::fromSimpleXMLElement方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::fromSimpleXMLElement方法的具体用法?PHP Tag::fromSimpleXMLElement怎么用?PHP Tag::fromSimpleXMLElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tag
的用法示例。
在下文中一共展示了Tag::fromSimpleXMLElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTopTags
/** Get the top tags used by this user.
*
* @param string $user The user name to fetch top tags for. (Required)
* @param integer $limit Limit the number of tags returned. (Optional)
* @return array An array of Tag objects.
*
* @static
* @access public
* @throws Error
*/
public static function getTopTags($user, $limit = null)
{
$xml = CallerFactory::getDefaultCaller()->call('user.getTopTags', array('user' => $user, 'limit' => $limit));
$tags = array();
foreach ($xml->children() as $tag) {
$tags[] = Tag::fromSimpleXMLElement($tag);
}
return $tags;
}
示例2: fromSimpleXMLElement
/** Create a Track object from a SimpleXMLElement.
*
* @param SimpleXMLElement $xml A SimpleXMLElement.
* @return Track A Track object.
*
* @static
* @access public
* @internal
*/
public static function fromSimpleXMLElement(SimpleXMLElement $xml)
{
$images = array();
$topTags = array();
if (count($xml->image) > 1) {
foreach ($xml->image as $image) {
$images[Util::toImageType($image['size'])] = Util::toString($image);
}
} else {
$images[Media::IMAGE_UNKNOWN] = Util::toString($xml->image);
}
if ($xml->toptags) {
foreach ($xml->toptags->children() as $tag) {
$topTags[] = Tag::fromSimpleXMLElement($tag);
}
}
if ($xml->artist) {
if ($xml->artist->name && $xml->artist->mbid && $xml->artist->url) {
$artist = new Artist(Util::toString($xml->artist->name), Util::toString($xml->artist->mbid), Util::toString($xml->artist->url), array(), 0, 0, 0, array(), array(), '', 0.0);
} else {
$artist = Util::toString($xml->artist);
}
} else {
if ($xml->creator) {
$artist = Util::toString($xml->creator);
} else {
$artist = '';
}
}
if ($xml->name) {
$name = Util::toString($xml->name);
} else {
if ($xml->title) {
$name = Util::toString($xml->title);
} else {
$name = '';
}
}
// TODO: <extension application="http://www.last.fm">
return new Track($artist, Util::toString($xml->album), $name, Util::toString($xml->mbid), Util::toString($xml->url), $images, Util::toInteger($xml->listeners), Util::toInteger($xml->playcount), Util::toInteger($xml->duration), $topTags, Util::toInteger($xml->id), Util::toString($xml->location), Util::toBoolean($xml->streamable), Util::toBoolean($xml->streamable['fulltrack']), $xml->wiki, Util::toTimestamp($xml->date));
}
示例3: fromSimpleXMLElement
/** Create an Artist object from a SimpleXMLElement object.
*
* @param SimpleXMLElement $xml A SimpleXMLElement object.
* @return Artist An Artist object.
*
* @static
* @access public
* @internal
*/
public static function fromSimpleXMLElement(SimpleXMLElement $xml)
{
$images = array();
$tags = array();
$similar = array();
/* NOTE: image, image_small... this sucks! */
if ($xml->image) {
if (count($xml->image) > 1) {
foreach ($xml->image as $image) {
$images[Util::toImageType($image['size'])] = Util::toString($image);
}
} else {
$images[Media::IMAGE_LARGE] = Util::toString($image);
}
}
if ($xml->image_small) {
$images[Media::IMAGE_SMALL] = Util::toString($xml->image_small);
}
if ($xml->tags) {
foreach ($xml->tags->children() as $tag) {
$tags[] = Tag::fromSimpleXMLElement($tag);
}
}
if ($xml->similar) {
foreach ($xml->similar->children() as $artist) {
$similar[] = Artist::fromSimpleXMLElement($artist);
}
}
return new Artist(Util::toString($xml->name), Util::toString($xml->mbid), Util::toString($xml->url), $images, Util::toBoolean($xml->streamable), Util::toInteger($xml->listeners), Util::toInteger($xml->playcount), $tags, $similar, $xml->bio ? Util::toString($xml->bio->summary) : "", Util::toFloat($xml->match));
}
示例4: search
/** Search for a tag by name. Returns matches sorted by relevance.
*
* @param string $tag The tag name in question. (Required)
* @param integer $limit Limit the number of tags returned at one time. Default (maximum) is 30. (Optional)
* @param integer $page Scan into the results by specifying a page number. Defaults to first page. (Optional)
* @return array An array of Tag objects.
*
* @static
* @access public
* @throws Error
*/
public static function search($tag, $limit = null, $page = null)
{
$xml = CallerFactory::getDefaultCaller()->call('tag.search', array('tag' => $tag, 'limit' => $limit, 'page' => $page));
$tags = array();
foreach ($xml->tagmatches->children() as $tag) {
$tags[] = Tag::fromSimpleXMLElement($tag);
}
return $tags;
}
示例5: fromSimpleXMLElement
/** Create an Album object from a SimpleXMLElement object.
*
* @param SimpleXMLElement $xml A SimpleXMLElement object.
* @return Album An Album object.
*
* @static
* @access public
* @internal
*/
public static function fromSimpleXMLElement(SimpleXMLElement $xml)
{
$images = array();
$topTags = array();
/* TODO: tagcount | library.getAlbums */
if ($xml->mbid) {
$mbid = Util::toString($xml->mbid);
} else {
if ($xml['mbid']) {
$mbid = Util::toString($xml['mbid']);
} else {
$mbid = '';
}
}
foreach ($xml->image as $image) {
$images[Util::toImageType($image['size'])] = Util::toString($image);
}
if ($xml->toptags) {
foreach ($xml->toptags->children() as $tag) {
$topTags[] = Tag::fromSimpleXMLElement($tag);
}
}
if ($xml->artist->name && $xml->artist->mbid && $xml->artist->url) {
$artist = new Artist(Util::toString($xml->artist->name), Util::toString($xml->artist->mbid), Util::toString($xml->artist->url), array(), 0, 0, 0, array(), array(), '', 0.0);
} else {
if ($xml->artist && $xml->artist['mbid']) {
$artist = new Artist(Util::toString($xml->artist), Util::toString($xml->artist['mbid']), '', array(), 0, 0, 0, array(), array(), '', 0.0);
} else {
$artist = Util::toString($xml->artist);
}
}
return new Album($artist, Util::toString($xml->name), Util::toInteger($xml->id), $mbid, Util::toString($xml->url), $images, Util::toInteger($xml->listeners), Util::toInteger($xml->playcount), Util::toTimestamp($xml->releasedate), $topTags);
}