本文整理汇总了PHP中Q_Request::cacheTimestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP Q_Request::cacheTimestamp方法的具体用法?PHP Q_Request::cacheTimestamp怎么用?PHP Q_Request::cacheTimestamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q_Request
的用法示例。
在下文中一共展示了Q_Request::cacheTimestamp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cachedUrl
/**
* This function is very useful to use with clients like PhoneGap which can
* intercept URLs and load whatever locally cached files are stored in their bundle.
* The urls for these files will be relative to the cache base url.
* (See Q_Uri::cacheBaseUrl function).
* In this case, the client is supposed to send the timestamp of when the
* cache it is using was generated.
* This function checks the current contents of the Q/config/Q/urls.php file,
* generated by scripts/Q/urls.php script.
* If the url's timestamp there is newer than the Q_Request::cacheTimestamp()
* (which the client can set by setting the 'Q_ct' field in the querystring)
* then that means the server has a newer version of the file, so the passed
* $url is used instead.
* Otherwise, the url relative to cacheBaseUrl is used, making the client
* load the locally cached version.
*/
static function cachedUrl($url)
{
$timestamp = Q_Request::cacheTimestamp();
if (empty($timestamp)) {
return $url;
}
$urlRelativeToBase = substr($url, strlen(Q_Request::baseUrl()));
$fileTimestamp = isset(Q_Uri::$urls[$urlRelativeToBase]) ? Q_Uri::$urls[$urlRelativeToBase] : null;
if (isset($fileTimestamp) and $fileTimestamp <= $timestamp and self::$cacheBaseUrl) {
return self::$cacheBaseUrl . $urlRelativeToBase;
}
return $url;
}
示例2: cachedUrl
/**
* This function is very useful to use with clients like PhoneGap which can
* intercept URLs and load whatever locally cached files are stored in their bundle.
* The urls for these files will be relative to the cache base url.
* (See Q_Uri::cacheBaseUrl function).
* In this case, the client is supposed to send the timestamp of when the
* cache it is using was generated.
* This function checks the current contents of the Q/config/Q/urls.php file,
* generated by scripts/Q/urls.php script.
* If the url's timestamp there is newer than the Q_Request::cacheTimestamp()
* (which the client can set by setting the 'Q_ct' field in the querystring)
* then that means the server has a newer version of the file, so the passed
* $url is used instead.
* Otherwise, the url relative to cacheBaseUrl is used, making the client
* load the locally cached version.
*/
static function cachedUrl($url)
{
$timestamp = Q_Request::cacheTimestamp();
if (empty($timestamp)) {
return $url;
}
$urlRelativeToBase = substr($url, strlen(Q_Request::baseUrl(false, true)));
$parts = explode('/', $urlRelativeToBase);
$parts[] = null;
$tree = new Q_Tree(Q_Uri::$urls);
$fileTimestamp = call_user_func_array(array($tree, 'get'), $parts);
if (isset($fileTimestamp) and $fileTimestamp <= $timestamp and self::$cacheBaseUrl) {
return self::$cacheBaseUrl . $urlRelativeToBase;
}
return $url;
}