Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
serviceadapter.php
1<?php
2
4
5
8
10{
11 private const CLASS_PREFIX = 'generatedWrapper';
12 private const CLASS_KEY_LENGTH = 16;
13
15 protected $wrapper;
16
21 private static function generateServiceWrapperContainerName() : string
22 {
23 return static::CLASS_PREFIX . Random::getStringByAlphabet(static::CLASS_KEY_LENGTH, Random::ALPHABET_ALPHALOWER);
24 }
25
30 public final static function createServiceWrapperContainer() : ServiceWrapper
31 {
32 while ($serviceWrapperClassName = static::generateServiceWrapperContainerName())
33 {
34 if(!class_exists($serviceWrapperClassName,false))
35 {
36 eval("
37 class $serviceWrapperClassName extends Bitrix\Seo\BusinessSuite\ServiceWrapper
38 implements
39 Bitrix\Seo\Retargeting\IService,
40 Bitrix\Seo\Retargeting\IMultiClientService,
41 Bitrix\Seo\BusinessSuite\IInternalService
42 {}
43 ");
44 return $serviceWrapperClassName::getInstance();
45 }
46 }
47 }
48
53 public static function loadFacebookService(): ?ServiceAdapter
54 {
56 {
57
58 return (new static())->setWrapper($serviceWrapper);
59 }
60
61 return null;
62 }
63
70 public static function load($type): ?ServiceAdapter
71 {
72 if($serviceWrapper = Utils\ServicePool::getService($type))
73 {
74
75 return (new static())->setWrapper($serviceWrapper);
76 }
77
78 return null;
79 }
80
86 public function canUse() : bool
87 {
88 if(isset($this->wrapper))
89 {
90
91 return $this->getWrapper()::getAuthAdapter($this->wrapper->getMetaData()->getType())->hasAuth();
92 }
93
94 return false;
95 }
96
106 {
107 $this->wrapper = $wrapper;
108 return $this;
109 }
110
115 public function getWrapper() : ?ServiceWrapper
116 {
117 return $this->wrapper;
118 }
119
126 public function getConfig() : ?Config
127 {
128 if ($this->canUse())
129 {
130 return Config::create($this->wrapper->getMetaData()->getType())->setService($this->wrapper);
131 }
132 return null;
133 }
134
140 public function getExtension() : ?Extension
141 {
142 if ($this->canUse())
143 {
144 return Extension::create($this->wrapper->getMetaData()->getType())->setService($this->wrapper);
145 }
146 return null;
147 }
148
153 public function getConversion(): Conversion
154 {
155 return Conversion::create($this->wrapper->getMetaData()->getType())->setService($this->wrapper);
156 }
157
158 public function getCatalog(): ?Catalog
159 {
160 if (!$this->canUse())
161 {
162 return null;
163 }
164
165 $metaData = $this->wrapper->getMetaData();
166 if (!$metaData || !$metaData->getType())
167 {
168 return null;
169 }
170
171 return Catalog::create($metaData->getType())->setService($this->wrapper);
172 }
173}
static create($type, $parameters=null, IService $service=null)