Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
rest.php
1<?php
2
4
9use CRestProvider;
11
16class Rest
17{
18 public const SCOPE = 'SCOPE';
19 public const METHOD = 'METHOD';
20 public const PLACEMENT = 'PLACEMENT';
21 public const EVENT = 'EVENT';
22 private const CACHE_TIME = 86400;
23 private const CACHE_DIR = '/rest/integration/data/rest/';
24
28 public static function getAllBasicDescription() : array
29 {
30 $result = [
31 static::SCOPE => [],
32 static::METHOD => [],
33 static::PLACEMENT => [],
34 static::EVENT => [],
35 ];
36 $cache = Cache::createInstance();
37 if ($cache->initCache(static::CACHE_TIME, 'allRestDescription' . LANGUAGE_ID, static::CACHE_DIR))
38 {
39 $result = $cache->getVars();
40 }
41 elseif ($cache->startDataCache())
42 {
43 $provider = new CRestProvider();
44 $allScope = $provider->getDescription();
45
46 foreach ($allScope as $scope => $list)
47 {
48 foreach ($list as $method => $data)
49 {
50 if ($method === '_events')
51 {
52 if (!isset($result[static::EVENT][$scope]))
53 {
54 $result[static::EVENT][$scope] = [];
55 }
56 $result[static::EVENT][$scope] = array_merge($result[static::EVENT][$scope], array_keys($data));
57 }
58 elseif ($method === '_placements')
59 {
60 if (!isset($result[static::PLACEMENT][$scope]))
61 {
62 $result[static::PLACEMENT][$scope] = [];
63 }
64 $result[static::PLACEMENT][$scope] = array_merge($result[static::PLACEMENT][$scope], array_keys($data));
65 }
66 else
67 {
68 $result[static::METHOD][$scope][] = $method;
69 }
70 }
71 }
72 $result[static::SCOPE] = array_keys($allScope);
73 $installedModuleList = ModuleManager::getInstalledModules();
74 foreach ($installedModuleList as $moduleId => $moduleDescription)
75 {
76 if (!isset($description[$moduleId]))
77 {
78 $controllersConfig = Configuration::getInstance($moduleId);
79
80 if (!empty($controllersConfig['controllers']['restIntegration']['enabled']))
81 {
82 $result[static::SCOPE][] = RestManager::getModuleScopeAlias($moduleId);
83 }
84 }
85 }
86 $result[static::SCOPE] = array_values(array_unique($result[static::SCOPE]));
87
88 $cache->endDataCache($result);
89 }
90
91 return $result;
92 }
93
99 public static function getAccessPlacement($scopeList) : array
100 {
101 $result = [];
102 if (!is_array($scopeList))
103 {
104 return $result;
105 }
106 $placementList = static::getAllBasicDescription()[static::PLACEMENT];
107
108 $placementList = array_intersect_key($placementList, array_flip($scopeList));
109 foreach ($placementList as $values)
110 {
111 $result = array_merge($result, $values);
112 }
113
114 return $result;
115 }
116
120 public static function getBaseMethod() : array
121 {
122 $result = [];
123 $data = static::getAllBasicDescription();
124 if (!empty($data[static::METHOD]))
125 {
126 $result = $data[static::METHOD];
127 }
128
129 return $result;
130 }
131
135 public static function getScope() : array
136 {
137 return ScopeManager::getInstance()->listScope();
138 }
139}
static getModuleScopeAlias($moduleId)
static getAllBasicDescription()
Definition rest.php:28
static getAccessPlacement($scopeList)
Definition rest.php:99