Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
servicewrapper.php
1<?php
2
4
5
9
11{
13 protected $metaData;
14
16 protected static $authAdapterPool = [];
17
19 protected static $instance = [];
20
21 private function __construct()
22 {}
23
24 private function __clone()
25 {}
26
31 public static function getInstance(): ServiceWrapper
32 {
33 if (!static::$instance[$key = get_called_class()])
34 {
35 static::$instance[$key] = new static();
36 }
37
38 return static::$instance[$key];
39 }
40
44 public static function canUseMultipleClients() : ?bool
45 {
46 $internal = static::getInstance()->getMetaData()->getService();
47 return $internal instanceof Retargeting\IMultiClientService && $internal::canUseMultipleClients();
48 }
49
53 public function getClientId(): string
54 {
55 return $this->metaData->getClientId();
56 }
57
64 public function setClientId($clientId)
65 {
66 throw new NotImplementedException("method not implement");
67 }
68
74 public static function getEngineCode($type) : ?string
75 {
76 if($service = static::getInstance()->getMetaData()->getService())
77 {
78
79 return $service::getEngineCode($type);
80 }
81
82 return null;
83 }
84
88 public static function getTypes() : ?array
89 {
90 if($service = static::getInstance()->getMetaData()->getService())
91 {
92
93 return $service::getTypes();
94 }
95
96 return null;
97 }
98
105 public static function getAuthAdapter($type) : BusinessAuthAdapter
106 {
107 static::$authAdapterPool[$key] = static::$authAdapterPool[$key = get_called_class()] ?? [];
108 if (!array_key_exists($type,static::$authAdapterPool[$key]))
109 {
110 static::$authAdapterPool[$key][$type] = BusinessAuthAdapter::create($type)->setService(static::getInstance());
111 }
112
113 return static::$authAdapterPool[$key][$type];
114 }
115
119 public static function getTypeByEngine(string $engineCode): ?string
120 {
121 if($service = static::getInstance()->getMetaData()->getService())
122 {
123
124 return $service::getTypeByEngine($engineCode);
125 }
126
127 return null;
128 }
129
133 public static function canUseAsInternal(): bool
134 {
135 if($service = static::getInstance()->getMetaData()->getService())
136 {
137
138 return $service::canUseAsInternal();
139 }
140
141 return false;
142 }
143
147 public static function getMethodPrefix(): string
148 {
149 if(($meta = static::getInstance()->getMetaData()) && $service = $meta->getService())
150 {
151 return $service::getMethodPrefix();
152 }
153
154 return '';
155 }
156
165 {
166 $this->metaData = $metaData;
167
168 return $this;
169 }
170
175 public function getMetaData() : ?ServiceMetaData
176 {
177 return $this->metaData;
178 }
179};
static getTypeByEngine(string $engineCode)
setMeta(?ServiceMetaData $metaData)