本文整理汇总了PHP中Util::toInteger方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::toInteger方法的具体用法?PHP Util::toInteger怎么用?PHP Util::toInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Util
的用法示例。
在下文中一共展示了Util::toInteger方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getWeeklyChartList
/** Get a list of available charts for this group, expressed as date ranges which can be sent to the chart services.
*
* @param string $group The last.fm group name to fetch the charts list for. (Required)
* @return array An array of from/to unix timestamp pairs.
*
* @static
* @access public
* @throws Error
*/
public static function getWeeklyChartList($group)
{
$xml = CallerFactory::getDefaultCaller()->call('group.getWeeklyChartList', array('group' => $group));
$chartList = array();
foreach ($xml->children() as $chart) {
$chartList[] = array('from' => Util::toInteger($chart['from']), 'to' => Util::toInteger($chart['to']));
}
return $chartList;
}
示例2: getEvents
/** Get all events in a specific location by country or city name.
*
* @param string $location Specifies a location to retrieve events for (service returns nearby events by default). (Optional)
* @param float $lat Specifies a latitude value to retrieve events for (service returns nearby events by default). (Optional)
* @param float $long Specifies a longitude value to retrieve events for (service returns nearby events by default). (Optional)
* @param integer $distance Find events within a specified distance. (Optional)
* @param integer $page Display more results by pagination. (Optional)
* @return PaginatedResult A PaginatedResult object.
*
* @static
* @access public
* @throws Error
*/
public static function getEvents($location = null, $lat = null, $long = null, $distance = null, $page = null)
{
$xml = CallerFactory::getDefaultCaller()->call('geo.getEvents', array('location' => $location, 'lat' => $lat, 'long' => $long, 'distance' => $distance, 'page' => $page));
$events = array();
foreach ($xml->children() as $event) {
$events[] = Event::fromSimpleXMLElement($event);
}
$perPage = intval(ceil(Util::toInteger($xml['total']) / Util::toInteger($xml['totalpages'])));
return new PaginatedResult(Util::toInteger($xml['total']), (Util::toInteger($xml['page']) - 1) * $perPage, $perPage, $events);
}
示例3: getTracks
/** A paginated list of all the tracks in a user's library, with play counts and tag counts.
*
* @param string $user The user whose library you want to fetch. (Required)
* @param integer $limit Limit the amount of tracks returned (maximum/default is 50). (Optional)
* @param integer $page The page number you wish to scan to. (Optional)
* @return PaginatedResult A PaginatedResult object.
*
* @static
* @access public
* @throws Error
*/
public static function getTracks($user, $limit, $page)
{
$xml = CallerFactory::getDefaultCaller()->call('library.getTracks', array('user' => $user, 'limit' => $limit, 'page' => $page));
$tracks = array();
foreach ($xml->children() as $track) {
$tracks[] = Track::fromSimpleXMLElement($track);
}
$perPage = Util::toInteger($xml['perPage']);
return new PaginatedResult(Util::toInteger($xml['totalPages']) * $perPage, (Util::toInteger($xml['page']) - 1) * $perPage, $perPage, $tracks);
}
示例4: fromSimpleXMLElement
/** Create a User object from a SimpleXMLElement.
*
* @param SimpleXMLElement $xml A SimpleXMLElement.
* @return User A User object.
*
* @static
* @access public
* @internal
*/
public static function fromSimpleXMLElement(SimpleXMLElement $xml)
{
$images = array();
foreach ($xml->image as $image) {
$images[Util::toImageType($image['size'])] = Util::toString($image);
}
return new User(Util::toString($xml->name), Util::toString($xml->realname), Util::toString($xml->url), Util::toString($xml->lang), Util::toString($xml->country), Util::toInteger($xml->age), Util::toString($xml->gender), Util::toInteger($xml->subscriber), Util::toInteger($xml->playcount), Util::toInteger($xml->playlists), $images, $xml->recenttrack ? Track::fromSimpleXMLElement($xml->recenttrack) : null, Util::toFloat($xml->match), Util::toInteger($xml->weight), Util::toInteger($xml->registered['unixtime']));
}
示例5: 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));
}
示例6: internalCall
/** Send a query using a specified request-method.
*
* @param string $query Query to send. (Required)
* @param string $requestMethod Request-method for calling (defaults to 'GET'). (Optional)
* @return SimpleXMLElement A SimpleXMLElement object.
*
* @access private
* @internal
*/
protected function internalCall($params, $requestMethod = 'GET')
{
/* Create caching hash. */
$hash = Cache::createHash($params);
/* Check if response is cached. */
if ($this->cache != null && $this->cache->contains($hash) && !$this->cache->isExpired($hash)) {
/* Get cached response. */
$response = $this->cache->load($hash);
} else {
/* Build request query */
$query = http_build_query($params, '', '&');
/* Set request options. */
if ($requestMethod === 'POST') {
curl_setopt($this->curl, CURLOPT_URL, self::API_URL);
curl_setopt($this->curl, CURLOPT_POST, 1);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $query);
} else {
curl_setopt($this->curl, CURLOPT_URL, self::API_URL . '?' . $query);
curl_setopt($this->curl, CURLOPT_POST, 0);
}
/* Clear response headers. */
$this->headers = array();
/* Get response. */
$response = curl_exec($this->curl);
/* Cache it. */
if ($this->cache != null) {
if (array_key_exists('Expires', $this->headers)) {
$this->cache->store($hash, $response, strtotime($this->headers['Expires']));
} else {
$expiration = $this->cache->getPolicy()->getExpirationTime($params);
if ($expiration > 0) {
$this->cache->store($hash, $response, time() + $expiration);
}
}
}
}
/* Create SimpleXMLElement from response. */
$response = new SimpleXMLElement($response);
/* Return response or throw an error. */
if (Util::toString($response['status']) === 'ok') {
if ($response->children()->{0}) {
return $response->children()->{0};
}
} else {
throw new Error(Util::toString($response->error), Util::toInteger($response->error['code']));
}
}
示例7: fromSimpleXMLElement
/** Create a Event object from a SimpleXMLElement.
*
* @param SimpleXMLElement $xml A SimpleXMLElement.
* @return Event A Event object.
*
* @static
* @access public
* @internal
*/
public static function fromSimpleXMLElement(SimpleXMLElement $xml)
{
$artists = array();
$images = array();
if ($xml->artists) {
foreach ($xml->artists->artist as $artist) {
$artists[] = Util::toString($artist);
}
$artists['headliner'] = Util::toString($xml->artists->headliner);
}
if ($xml->image) {
foreach ($xml->image as $image) {
$images[Util::toImageType($image['size'])] = Util::toString($image);
}
}
return new Event(Util::toInteger($xml->id), Util::toString($xml->title), $artists, $xml->venue ? Venue::fromSimpleXMLElement($xml->venue) : null, Util::toTimestamp($xml->startDate), Util::toString($xml->description), $images, Util::toString($xml->url), Util::toInteger($xml->attendance), Util::toInteger($xml->reviews), Util::toString($xml->tag));
}
示例8: fromSimpleXMLElement
/** Create a Tag object from a SimpleXMLElement.
*
* @param SimpleXMLElement $xml A SimpleXMLElement.
* @return Tag A Tag object.
*
* @static
* @access public
* @internal
*/
public static function fromSimpleXMLElement(SimpleXMLElement $xml)
{
return new Tag(Util::toString($xml->name), Util::toInteger($xml->count), Util::toString($xml->url));
}
示例9: fromSimpleXMLElement
/** Create a Playlist object from a SimpleXMLElement.
*
* @param SimpleXMLElement $xml A SimpleXMLElement object.
* @return Playlist A Playlist object.
*
* @static
* @access public
* @internal
*/
public static function fromSimpleXMLElement(SimpleXMLElement $xml)
{
$tracks = array();
if (isset($xml->trackList)) {
foreach ($xml->trackList->children() as $track) {
$tracks[] = Track::fromSimpleXMLElement($track);
}
}
return new Playlist(Util::toInteger($xml->id), Util::toString($xml->title), Util::toString($xml->description), Util::toTimestamp($xml->date), Util::toInteger($xml->size), Util::toInteger($xml->duration), Util::toInteger($xml->streamable), Util::toString($xml->creator), Util::toString($xml->url), $tracks);
}
示例10: search
/** Search for a venue by venue name .
*
* @param string $venue The venue name you would like to search for. (Required)
* @param integer $limit The number of results to fetch per page. Defaults to 50. (Optional)
* @param integer $page The results page you would like to fetch. (Optional)
* @param string $country Filter your results by country. Expressed as an ISO 3166-2 code. (Optional)
* @return PaginatedResult A PaginatedResult object.
* @see PaginatedResult
*
* @static
* @access public
* @throws Error
*/
public static function search($venue, $limit = null, $page = null, $country = null)
{
$xml = CallerFactory::getDefaultCaller()->call('venue.search', array('venue' => $venue, 'limit' => $limit, 'page' => $page, 'country' => $country));
$venues = array();
foreach ($xml->venuematches->children() as $venue) {
$venues[] = Venue::fromSimpleXMLElement($venue);
}
$opensearch = $xml->children('http://a9.com/-/spec/opensearch/1.1/');
return new PaginatedResult(Util::toInteger($opensearch->totalResults), Util::toInteger($opensearch->startIndex), Util::toInteger($opensearch->itemsPerPage), $venues);
}
示例11: 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));
}
示例12: internalCall
/** Send a query using a specified request-method.
*
* @param string $query Query to send. (Required)
* @param string $requestMethod Request-method for calling (defaults to 'GET'). (Optional)
* @return SimpleXMLElement A SimpleXMLElement object.
*
* @access private
* @internal
*/
protected function internalCall($params, $requestMethod = 'GET')
{
/* Create caching hash. */
$hash = Cache::createHash($params);
/* Check if response is cached. */
if ($this->cache != null && $this->cache->contains($hash) && !$this->cache->isExpired($hash)) {
/* Get cached response. */
$response = $this->cache->load($hash);
} else {
/* Build request query. */
$query = http_build_query($params, '', '&');
/* Extract URL information. */
$info = parse_url(self::API_URL);
/* TODO: Accept-Encoding: deflate, gzip */
/* Set request data. */
if ($requestMethod === 'POST') {
$data = "POST " . $info['path'] . " HTTP/1.1\r\n";
$data .= "Host: " . $info['host'] . "\r\n";
$data .= "User-Agent: PHP last.fm API (PHP/" . phpversion() . ")\r\n";
$data .= "Content-Type: application/x-www-form-urlencoded\r\n";
$data .= "Content-Length: " . strlen($query) . "\r\n";
$data .= "Connection: Close\r\n\r\n";
$data .= $query;
} else {
$data = "GET " . $info['path'] . "?" . $query . " HTTP/1.1\r\n";
$data .= "Host: " . $info['host'] . "\r\n";
$data .= "User-Agent: PHP last.fm API (PHP/" . phpversion() . ")\r\n";
$data .= "Connection: Close\r\n\r\n";
}
/* Open socket. */
$socket = fsockopen($info['host'], 80);
/* Write request. */
fwrite($socket, $data);
/* Clear response headers. */
$this->headers = array();
/* Read headers. */
while (($line = fgets($socket)) !== false && $line != "\r\n") {
$this->header($line);
}
/* Read response. */
$response = "";
while (($line = fgets($socket)) !== false && $line != "\r\n") {
$response .= $line;
}
/* Close socket. */
fclose($socket);
/* Cache it. */
if ($this->cache != null) {
if (array_key_exists('Expires', $this->headers)) {
$this->cache->store($hash, $response, strtotime($this->headers['Expires']));
} else {
$expiration = $this->cache->getPolicy()->getExpirationTime($params);
if ($expiration > 0) {
$this->cache->store($hash, $response, time() + $expiration);
}
}
}
}
/* Create SimpleXMLElement from response. */
$response = new SimpleXMLElement($response);
/* Return response or throw an error. */
if (Util::toString($response['status']) === 'ok') {
if ($response->children()->{0}) {
return $response->children()->{0};
}
} else {
throw new Error(Util::toString($response->error), Util::toInteger($response->error['code']));
}
}
示例13: 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);
}
示例14: internalCall
/** Send a query using a specified request-method.
*
* @param string $query Query to send. (Required)
* @param string $requestMethod Request-method for calling (defaults to 'GET'). (Optional)
* @return SimpleXMLElement A SimpleXMLElement object.
*
* @access protected
* @internal
*/
protected function internalCall($params, $requestMethod = 'GET')
{
/* Create caching hash. */
$hash = Cache::createHash($params);
/* Check if response is cached. */
if ($this->cache != null && $this->cache->contains($hash) && !$this->cache->isExpired($hash)) {
/* Get cached response. */
$response = $this->cache->load($hash);
} else {
/* Build request query. */
$query = http_build_str($params, '', '&');
/* Set request options. */
$options = array('useragent' => 'PHP last.fm API (PHP/' . phpversion() . ')');
/* Clear response headers. */
$this->headers = array();
/* Get response */
if ($requestMethod === 'POST') {
$response = http_post_data(self::API_URL, $query, $options, $info);
} else {
$response = http_get(self::API_URL . '?' . $query, $options, $info);
}
$response = http_parse_message($response);
foreach ($response->headers as $header => $value) {
$this->headers[$header] = $value;
}
$response = $response->body;
/* Cache it. */
if ($this->cache != null) {
if (array_key_exists('Expires', $this->headers)) {
$this->cache->store($hash, $response, strtotime($this->headers['Expires']));
} else {
$expiration = $this->cache->getPolicy()->getExpirationTime($params);
if ($expiration > 0) {
$this->cache->store($hash, $response, time() + $expiration);
}
}
}
}
/* Create SimpleXMLElement from response. */
$response = new SimpleXMLElement($response);
/* Return response or throw an error. */
if (Util::toString($response['status']) === 'ok') {
if ($response->children()->{0}) {
return $response->children()->{0};
}
} else {
throw new Error(Util::toString($response->error), Util::toInteger($response->error['code']));
}
}