Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
service.php
1<?php
2
3namespace Bitrix\Seo\LeadAds;
4
8
15{
16 public const GROUP = 'leadads';
17
18 public const TYPE_FACEBOOK = 'facebook';
19
20 public const TYPE_VKONTAKTE = 'vkontakte';
21
23 protected $accounts = [];
24
26 protected $forms = [];
27
36 public static function registerGroup(string $type, string $groupId): bool
37 {
38 return Form::create($type)
39 ->setService(static::getInstance())
40 ->registerGroup($groupId);
41 }
42
48 public static function getInstance(): Service
49 {
50 static $instance;
51
52 return $instance = $instance ?? new static();
53 }
54
63 public static function unRegisterGroup(string $type, string $groupId): bool
64 {
65 $result = Form::create($type)
66 ->setService(static::getInstance())
67 ->unRegisterGroup($groupId);
68
69 static::getInstance()->getGroupAuth($type)->removeAuth();
70
71 return $result;
72 }
73
80 public static function getAuthAdapter($type): AuthAdapter
81 {
83 static $adapters;
84
85 $adapters = $adapters ?? [];
86 if (!array_key_exists($type, $adapters))
87 {
88 $adapters[$type] = AuthAdapter::create($type)->setService(static::getInstance());
89 }
90
91 return $adapters[$type];
92 }
93
97 public static function getTypeByEngine(string $engineCode): ?string
98 {
99 foreach (static::getTypes() as $type)
100 {
101 if ($engineCode === static::getEngineCode($type))
102 {
103 return $type;
104 }
105 }
106
107 return null;
108 }
109
115 public static function getTypes(): array
116 {
117 return [
118 static::TYPE_FACEBOOK,
119 static::TYPE_VKONTAKTE,
120 ];
121 }
122
129 public static function getEngineCode($type): string
130 {
131 return static::GROUP . '.' . $type;
132 }
133
137 public static function canUseAsInternal(): bool
138 {
139 return true;
140 }
141
145 public static function getMethodPrefix(): string
146 {
147 return 'leadads';
148 }
149
157 public function getGroupAuth(string $type): ?AuthAdapter
158 {
159 return $this->getForm($type)->getGroupAuthAdapter();
160 }
161
169 public function getForm(string $type): Form
170 {
171 if (!array_key_exists($type, $this->forms))
172 {
173 $this->forms[$type] = Form::create($type)->setService($this);
174 }
175
176 return $this->forms[$type];
177 }
178
186 public function getAccount(string $type): ?Account
187 {
188 if (!array_key_exists($type, $this->accounts))
189 {
190 $this->accounts[$type] = Account::create($type)->setService($this);
191 }
192
193 return $this->accounts[$type];
194 }
195
196 public function getAuthUrl($type): string
197 {
198 $authManager = static::getAuthAdapter($type);
199 return $authManager->getAuthUrl();
200 }
201}
202
static getEngineCode($type)
Definition service.php:129
static unRegisterGroup(string $type, string $groupId)
Definition service.php:63
static registerGroup(string $type, string $groupId)
Definition service.php:36
static getTypeByEngine(string $engineCode)
Definition service.php:97
getGroupAuth(string $type)
Definition service.php:157
getAccount(string $type)
Definition service.php:186