-
Notifications
You must be signed in to change notification settings - Fork 1
/
ManifestAction.php
40 lines (32 loc) · 1.18 KB
/
ManifestAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace mdm\tools;
use Yii;
/**
* Description of ManifestAction
*
* @author MDMunir
*/
class ManifestAction extends \yii\base\Action
{
public function run($id, $forceUpdate = false)
{
$keyCache = [AppCache::CACHE_KEY, $id];
if (($cache = Yii::$app->cache) && ($data = $cache->get($keyCache)) !== false) {
$key = [AppCache::CACHE_KEY, $id];
$key[] = !empty($data['uniqueForClient']) && isset(Yii::$app->clientUniqueid) ? Yii::$app->clientUniqueid : false;
$key[] = !empty($data['uniqueForUser']) ? Yii::$app->user->getId() : false;
$time = $forceUpdate === false ? $cache->get($key) : false;
if ($time === false) {
$time = date('Y-m-d H:i:s');
$cache->set($key, $time);
}
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
Yii::$app->response->headers->set('Content-Type', 'text/cache-manifest');
$manifest = Yii::$app->getView()->renderFile($data['template_file'], [
'caches' => $data['caches'],
'time' => $time]);
return $manifest;
}
return '';
}
}