本文整理汇总了PHP中Assetic\Asset\AssetInterface::getLastModified方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetInterface::getLastModified方法的具体用法?PHP AssetInterface::getLastModified怎么用?PHP AssetInterface::getLastModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assetic\Asset\AssetInterface
的用法示例。
在下文中一共展示了AssetInterface::getLastModified方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
public function process(AssetInterface $asset)
{
$hash = hash_init('sha1');
switch ($this->strategy) {
case self::STRATEGY_MODIFICATION:
hash_update($hash, $asset->getLastModified());
break;
case self::STRATEGY_CONTENT:
hash_update($hash, $asset->dump());
break;
}
foreach ($asset as $i => $leaf) {
if ($sourcePath = $leaf->getSourcePath()) {
hash_update($hash, $sourcePath);
} else {
hash_update($hash, $i);
}
}
$hash = substr(hash_final($hash), 0, 7);
$url = $asset->getTargetPath();
$oldExt = pathinfo($url, PATHINFO_EXTENSION);
$newExt = '-' . $hash . '.' . $oldExt;
if (!$oldExt || 0 < preg_match('/' . preg_quote($newExt, '/') . '$/', $url)) {
return;
}
$asset->setTargetPath(substr($url, 0, (strlen($oldExt) + 1) * -1) . $newExt);
}
示例2: __construct
/**
* @param AssetInterface $asset
* @param AssetWriter $writer
* @param array $cachePath
* @param array $headers
*/
public function __construct(AssetInterface $asset, AssetWriter $writer, $cachePath, array $headers = [])
{
$file = $asset->getTargetPath();
$cachePath = $cachePath . '/' . $file;
$cached = false;
$cacheTime = time();
if (is_file($cachePath)) {
$mTime = $asset->getLastModified();
$cacheTime = filemtime($cachePath);
if ($mTime > $cacheTime) {
@unlink($cachePath);
$cacheTime = $mTime;
} else {
$cached = true;
}
}
if (!$cached) {
$writer->writeAsset($asset);
}
$stream = function () use($cachePath) {
readfile($cachePath);
};
$headers['Content-Length'] = filesize($cachePath);
if (preg_match('/.+\\.([a-zA-Z0-9]+)/', $file, $matches)) {
$ext = $matches[1];
if (isset($this->mimeTypes[$ext])) {
$headers['Content-Type'] = $this->mimeTypes[$ext];
}
}
parent::__construct($stream, 200, $headers);
$date = new \DateTime();
$date->setTimestamp($cacheTime);
$this->setLastModified($date);
}
示例3: getLastModified
/**
* {@inheritdoc}
*/
public function getLastModified()
{
if (!$this->innerAsset) {
$this->createInnerAsset();
}
return $this->innerAsset->getLastModified();
}
示例4: writeAsset
public function writeAsset(AssetInterface $asset)
{
foreach (VarUtils::getCombinations($asset->getVars(), $this->values) as $combination) {
$asset->setValues($combination);
$path = $this->dir . '/' . VarUtils::resolve($asset->getTargetPath(), $asset->getVars(), $asset->getValues());
if (!is_dir($path) && (!file_exists($path) || filemtime($path) <= $asset->getLastModified())) {
static::write($path, $asset->dump());
}
}
}
示例5: process
public function process(AssetInterface $asset, AssetFactory $factory)
{
$path = $asset->getTargetPath();
$ext = pathinfo($path, PATHINFO_EXTENSION);
$lastModified = $asset->getLastModified();
if (null !== $lastModified) {
$path = substr_replace($path, "{$lastModified}.{$ext}", -1 * strlen($ext));
$asset->setTargetPath($path);
}
}
示例6: helper
/**
* @param AssetInterface $asset
* @param array $options
* @return string
*/
protected function helper(AssetInterface $asset, array $options = array())
{
$path = $this->baseUrl . $this->basePath . $asset->getTargetPath();
$extension = pathinfo($path, PATHINFO_EXTENSION);
$extension = strtolower($extension);
if (isset($options['addFileMTime']) && $options['addFileMTime']) {
$path .= '?' . $asset->getLastModified();
}
switch ($extension) {
case 'js':
return $this->getScriptTag($path, $options);
case 'css':
return $this->getStylesheetTag($path, $options);
}
return '';
}
示例7: dumpAsset
private function dumpAsset(AssetInterface $asset)
{
// HTTP caching
$mtime = gmdate('D, d M y H:i:s', $asset->getLastModified()) . 'GMT';
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && ($mtime = $_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
header('HTTP/1.1 304 Not Modified');
exit;
}
// set headers & dump asset
$extension = pathinfo($asset->getTargetPath(), PATHINFO_EXTENSION);
if (array_key_exists($extension, self::$extensionsToMimeTypes)) {
$mimeType = self::$extensionsToMimeTypes[$extension];
header("Content-Type: {$mimeType}");
header("Last-Modified: {$mtime}");
header('Cache-Control: public');
}
echo $asset->dump();
exit;
}
示例8: getCacheKey
/**
* @param AssetInterface $asset
* @return string
*/
protected function getCacheKey(AssetInterface $asset)
{
$cacheKey = '';
if ($asset instanceof AssetCollectionInterface) {
foreach ($asset->all() as $childAsset) {
$cacheKey .= $childAsset->getSourcePath();
$cacheKey .= $childAsset->getLastModified();
}
} else {
$cacheKey .= $asset->getSourcePath();
$cacheKey .= $asset->getLastModified();
}
foreach ($asset->getFilters() as $filter) {
if ($filter instanceof HashableInterface) {
$cacheKey .= $filter->hash();
} else {
$cacheKey .= serialize($filter);
}
}
return md5($cacheKey);
}
示例9: setupAsset
public function setupAsset(AssetInterface $asset)
{
$path = $this->getBaseUrl() . $asset->getTargetPath();
return $this->helper($path, $asset->getLastModified());
}
示例10: getLastModified
public function getLastModified(AssetInterface $asset)
{
$mtime = $asset->getLastModified();
if (!($filters = $asset->getFilters())) {
return $mtime;
}
// prepare load path
$sourceRoot = $asset->getSourceRoot();
$sourcePath = $asset->getSourcePath();
$loadPath = $sourceRoot && $sourcePath ? dirname($sourceRoot . '/' . $sourcePath) : null;
$prevFilters = array();
foreach ($filters as $filter) {
$prevFilters[] = $filter;
if (!$filter instanceof DependencyExtractorInterface) {
continue;
}
// extract children from asset after running all preceeding filters
$clone = clone $asset;
$clone->clearFilters();
foreach (array_slice($prevFilters, 0, -1) as $prevFilter) {
$clone->ensureFilter($prevFilter);
}
$clone->load();
foreach ($filter->getChildren($this->factory, $clone->getContent(), $loadPath) as $child) {
$mtime = max($mtime, $this->getLastModified($child));
}
}
return $mtime;
}
示例11: getLastModified
/**
* Returns the time the current asset was last modified.
*
* @return integer|null A UNIX timestamp
*/
public function getLastModified()
{
return $this->asset->getLastModified();
}
示例12: is_stale
protected function is_stale(AssetInterface $asset)
{
$stale = TRUE;
$target = $asset->getTargetPath();
if (file_exists($target)) {
$last = filemtime($target);
$mod = $asset->getLastModified();
if ($mod && $last >= $mod) {
$stale = FALSE;
}
}
return $stale;
}