Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
immune.php
1<?php
2
4
8
13class Immune
14{
15 private const OPTION_APP_IMMUNE_LIST = 'app_immune';
16 private const MODULE_ID = 'rest';
17 private const CACHE_TTL_TIMEOUT = 120;
18 private const CACHE_DIR = '/rest/';
19 private static $immuneAppList;
20
24 public static function getList() : array
25 {
26 if (!is_array(static::$immuneAppList))
27 {
28 static::$immuneAppList = [];
29 try
30 {
31 $option = Option::get(static::MODULE_ID, static::OPTION_APP_IMMUNE_LIST, null);
32
33 if ($option === null)
34 {
35 $option = static::getExternal();
36 }
37
38 if (!empty($option))
39 {
40 static::$immuneAppList = Json::decode($option);
41 }
42 else
43 {
44 static::$immuneAppList = [];
45 }
46 }
47 catch (\Exception $exception)
48 {
49 static::$immuneAppList = [];
50 }
51 }
52
53 return static::$immuneAppList;
54 }
55
56 private static function getExternal()
57 {
58 $result = false;
59 $cache = Cache::createInstance();
60 if ($cache->initCache(static::CACHE_TTL_TIMEOUT, 'immuneLoadsRepeatingTimeout', static::CACHE_DIR))
61 {
62 $result = $cache->getVars();
63 }
64 elseif ($cache->startDataCache())
65 {
66 $res = Client::getImmuneApp();
67 if (!empty($res['ITEMS']))
68 {
69 $result = Json::encode($res['ITEMS']);
70 Option::set(static::MODULE_ID, static::OPTION_APP_IMMUNE_LIST, $result);
71 }
72
73 $cache->endDataCache($result);
74 }
75
76 return $result;
77 }
78
83 public static function load() : string
84 {
85 static::getExternal();
86
87 return '\Bitrix\Rest\Marketplace\Immune::load();';
88 }
89}