Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
authadapter.php
1<?php
2
4
8use Bitrix\Seo\Service as SeoService;
9
15{
17 protected $service;
18 protected $type;
19 protected $data;
20
22 protected $parameters = ['URL_PARAMETERS' => []];
23
28 public function __construct($type)
29 {
30 $this->type = $type;
31 }
32
40 public static function create($type, IService $service = null)
41 {
42 if (!Loader::includeModule('socialservices'))
43 {
44 throw new SystemException('Module "socialservices" not installed.');
45 }
46 $instance = new static($type);
47 if ($service)
48 {
49 $instance->setService($service);
50 }
51
52 return $instance;
53 }
54
59 public function setService(IService $service)
60 {
61 $this->service = $service;
62 return $this;
63 }
64
69 public function setParameters(array $parameters = [])
70 {
71 $this->parameters = $parameters + $this->parameters;
72 return $this;
73 }
74
79 public function getAuthUrl()
80 {
82 {
84 }
85
86 $authorizeUrl = SeoService::getAuthorizeLink();
87 $authorizeData = SeoService::getAuthorizeData($this->getEngineCode());
88 $uri = new Uri($authorizeUrl);
89 if (!empty($this->parameters['URL_PARAMETERS']))
90 {
91 $authorizeData['urlParameters'] = $this->parameters['URL_PARAMETERS'];
92 }
93 $uri->addParams($authorizeData);
94 return $uri->getLocator();
95 }
96
101 protected function getAuthData($isUseCache = true)
102 {
103 if (!$isUseCache || !$this->data || count($this->data) == 0)
104 {
105 $this->data = SeoService::getAuth($this->getEngineCode());
106 }
107
108 return $this->data;
109 }
110
111 public function removeAuth()
112 {
113 $this->data = array();
114
115 if ($existedAuthData = $this->getAuthData(false))
116 {
118 }
119 }
120
124 protected function getEngineCode()
125 {
126 if ($this->service)
127 {
128 return $this->service->getEngineCode($this->type);
129 }
130 else
131 {
132 return Service::getEngineCode($this->type);
133 }
134 }
135
139 public function getType()
140 {
141 return $this->type;
142 }
143
147 public function getToken()
148 {
149 $data = $this->getAuthData();
150 return $data ? $data['access_token'] : null;
151 }
152
156 public function hasAuth()
157 {
158 return $this->getToken() <> '';
159 }
160}
static create($type, IService $service=null)
setParameters(array $parameters=[])
setService(IService $service)
static getEngineCode($type)
Definition service.php:35
static getAuthorizeLink()
Definition service.php:333
static getAuth(string $engineCode)
Definition service.php:72
static isRegistered()
Definition service.php:59
static register()
Definition service.php:293
static clearAuth($engineCode, $localOnly=false)
Definition service.php:212
static getAuthorizeData($engine, $clientType=false)
Definition service.php:344