Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
staticarea.php
1<?
3
4use Bitrix\Main\Page\Asset;
6
8{
9 private $id = null;
10 private $stub = "";
11 private $containerId = null;
12 private $useBrowserStorage = false;
13 private $useAnimation = false;
14 private $autoUpdate = true;
15 private $assetMode = AssetMode::ALL;
16
20 private static $dynamicAreas = array();
21 private static $curDynamicId = false;
22 private static $containers = array();
23
24 function __construct($id)
25 {
26 $this->id = $id;
27 }
28
29 public function startDynamicArea()
30 {
31 if (isset(self::$dynamicAreas[$this->id])
32 || $this->id == self::$curDynamicId
33 || self::$curDynamicId !== false
34 )
35 {
36 return false;
37 }
38
39 echo '<!--\'start_frame_cache_'.$this->id.'\'-->';
40
41 self::$curDynamicId = $this->id;
42 self::addDynamicArea($this);
43
44 Asset::getInstance()->startTarget($this->getAssetId(), $this->assetMode);
45
46 return true;
47 }
48
49 public function finishDynamicArea()
50 {
51 if (self::$curDynamicId !== $this->id)
52 {
53 return false;
54 }
55
56 echo '<!--\'end_frame_cache_'.$this->id.'\'-->';
57
58 self::$curDynamicId = false;
59
60 Asset::getInstance()->stopTarget($this->getAssetId());
61
62 return true;
63 }
64
65 public static function addDynamicArea(StaticArea $area)
66 {
67 self::$dynamicAreas[$area->getId()] = $area;
68 }
69
73 public static function getDynamicIDs()
74 {
75 return array_keys(self::$dynamicAreas);
76 }
77
81 public static function getDynamicAreas()
82 {
83 return self::$dynamicAreas;
84 }
85
91 public static function getDynamicArea($id)
92 {
93 return self::$dynamicAreas[$id] ?? null;
94 }
95
99 public static function getCurrentDynamicArea()
100 {
101 if (self::$curDynamicId !== false && isset(self::$dynamicAreas[self::$curDynamicId]))
102 {
103 return self::$dynamicAreas[self::$curDynamicId];
104 }
105
106 return null;
107 }
108
109 public static function getCurrentDynamicId()
110 {
111 return self::$curDynamicId;
112 }
113
114 public static function getContainers()
115 {
116 return self::$containers;
117 }
118
119 public function getId()
120 {
121 return $this->id;
122 }
123
124 public function getAssetId()
125 {
126 return "frame_".$this->id;
127 }
128
129 public function setStub($stub)
130 {
131 $this->stub = $stub;
132 }
133
134 public function getStub()
135 {
136 return $this->stub;
137 }
138
139 public function setContainerId($containerId)
140 {
141 $this->containerId = $containerId;
142 if ($this->containerId !== null)
143 self::$containers[$this->id] = $containerId;
144 }
145
146 public function getContainerId()
147 {
148 return $this->containerId;
149 }
150
151 public function setBrowserStorage($useBrowserStorage)
152 {
153 $this->useBrowserStorage = $useBrowserStorage;
154 }
155
156 public function getBrowserStorage()
157 {
158 return $this->useBrowserStorage;
159 }
160
161 public function setAnimation($useAnimation)
162 {
163 $this->useAnimation = $useAnimation;
164 }
165
166 public function getAnimation()
167 {
168 return $this->useAnimation;
169 }
170
171 public function setAutoUpdate($autoUpdate)
172 {
173 $this->autoUpdate = $autoUpdate;
174 }
175
176 public function getAutoUpdate()
177 {
178 return $this->autoUpdate;
179 }
180
184 public function setAssetMode($mode)
185 {
186 // startDynamicArea wasn't invoked
187 if (self::getDynamicArea($this->id) === null)
188 {
189 $this->assetMode = $mode;
190 }
191 }
192
193 public function getAssetMode()
194 {
195 return $this->assetMode;
196 }
197
203 public function getCachedData()
204 {
205 return array(
206 "id" => $this->getId(),
207 "containerId" => $this->getContainerId(),
208 "staticPart" => $this->getStub(),
209 "useBrowserStorage" => $this->getBrowserStorage(),
210 "autoUpdate" => $this->getAutoUpdate(),
211 "useAnimation" => $this->getAnimation(),
212 );
213 }
214
222 public static function applyCachedData($cachedData)
223 {
224 $area = new static($cachedData["id"]);
225 $area->setStub($cachedData["staticPart"]);
226 $area->setContainerId($cachedData["containerId"]);
227 $area->setBrowserStorage($cachedData["useBrowserStorage"]);
228 $area->setAutoUpdate($cachedData["autoUpdate"]);
229 $area->setAnimation($cachedData["useAnimation"]);
230
232
233 return $area;
234 }
235}
236
237class_alias("Bitrix\\Main\\Composite\\StaticArea", "Bitrix\\Main\\Page\\FrameStatic");
static applyCachedData($cachedData)
static addDynamicArea(StaticArea $area)