Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
engine.php
1<?php
9namespace Bitrix\Rest\OAuth;
10
11
13use Bitrix\Main;
14
15class Engine
16{
17 protected $scope = array(
18 "rest", "application"
19 );
20
21 protected $client = null;
22
23 public function __construct()
24 {
25 }
26
27
31 public function getClient()
32 {
33 if(!$this->client)
34 {
35 $this->client = new Client(
36 $this->getClientId(),
37 $this->getClientSecret(),
38 $this->getLicense()
39 );
40 }
41
42 return $this->client;
43 }
44
45 public function isRegistered()
46 {
47 return $this->getClientId() !== false;
48 }
49
50 public function getClientId()
51 {
52 return Option::get("rest", "service_client_id", false);
53 }
54
55 public function getClientSecret()
56 {
57 return Option::get("rest", "service_client_secret", false);
58 }
59
60 public function setAccess(array $accessParams)
61 {
62 $connection = Main\Application::getInstance()->getConnection();
63 $connection->startTransaction();
64 try
65 {
66 Option::set("rest", "service_client_id", $accessParams["client_id"]);
67 Option::set("rest", "service_client_secret", $accessParams["client_secret"]);
68 $connection->commitTransaction();
69 }
70 catch (Main\ArgumentNullException $e)
71 {
72 $connection->rollbackTransaction();
73 }
74
75 $this->client = null;
76 }
77
78 public function clearAccess()
79 {
80 $this->setAccess(array(
81 "client_id" => false,
82 "client_secret" => false,
83 ));
84
85 $this->client = null;
86 }
87
88 public function getLicense()
89 {
90 return LICENSE_KEY;
91 }
92}
setAccess(array $accessParams)
Definition engine.php:60