Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
assets.php
1<?php
2
4
5class Assets
6{
7 public $component = null;
8
9 private static $assetFiles = [
10 '/bitrix/components/bitrix/socialnetwork.log.ex/templates/.default/style.css',
11 ];
12
13 public function __construct($params)
14 {
15 if (!empty($params['component']))
16 {
17 $this->component = $params['component'];
18 }
19 }
20
21 public function getComponent()
22 {
23 return $this->component;
24 }
25
26 public function checkRefreshNeeded(&$result): bool
27 {
28 $params = $this->getComponent()->arParams;
29 if (empty($params['assetsCheckSum']))
30 {
31 return true;
32 }
33
34 $currentAssetsCheckSum = self::getCheckSum();
35 if (empty($currentAssetsCheckSum))
36 {
37 return true;
38 }
39
40 if ($currentAssetsCheckSum === $params['assetsCheckSum'])
41 {
42 return true;
43 }
44
45 $result['FORCE_PAGE_REFRESH'] = 'Y';
46
47 return false;
48 }
49
50 public function getAssetsCheckSum(&$result): void
51 {
52 $result['ASSETS_CHECKSUM'] = self::getCheckSum();
53 }
54
55 public static function getCheckSum()
56 {
57 static $result = null;
58
59 if ($result !== null)
60 {
61 return $result;
62 }
63
64 $assetsData = [];
65
66 $documentRoot = \Bitrix\Main\Application::getDocumentRoot();
67 foreach(self::$assetFiles as $filePath)
68 {
69 $file = new \Bitrix\Main\IO\File($documentRoot . $filePath);
70 if (!$file->isExists())
71 {
72 continue;
73 }
74
75 $assetsData[] = [
76 $filePath => $file->getModificationTime()
77 ];
78 }
79
80 return md5(serialize($assetsData));
81 }
82}