Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
scope.php
1
<?php
2
3
namespace
Bitrix\Rest\Engine\ActionFilter
;
4
5
use
Bitrix\Main\Error
;
6
use
Bitrix\Main\Event
;
7
use
Bitrix\Main\EventResult
;
8
13
class
Scope
extends
Base
14
{
15
public
const
ERROR_INSUFFICIENT_SCOPE
=
'insufficient_scope'
;
16
17
private
$scopes;
18
19
public
function
__construct
(...$scopes)
20
{
21
$this->scopes = $scopes;
22
parent::__construct();
23
}
24
25
public
function
onBeforeAction
(
Event
$event)
26
{
27
$scopeList = $this->
getCurrentScope
();
28
29
$need = array_diff($this->scopes, $scopeList);
30
31
if
(!$need)
32
{
33
return
null
;
34
}
35
36
$this->addError(
37
new
Error
(
38
'The current method required more scopes. ('
. implode(
', '
, $need) .
')'
,
39
self::ERROR_INSUFFICIENT_SCOPE
40
)
41
);
42
43
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
44
}
45
46
protected
function
getCurrentScope
()
47
{
48
$server = $this->
getRestServer
();
49
if
($server)
50
{
51
return
$server->getAuthScope();
52
}
53
54
return
[];
55
}
56
}
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Rest\Engine\ActionFilter\Base
Definition
base.php:13
Bitrix\Rest\Engine\ActionFilter\Base\getRestServer
getRestServer()
Definition
base.php:28
Bitrix\Rest\Engine\ActionFilter\Scope
Definition
scope.php:14
Bitrix\Rest\Engine\ActionFilter\Scope\ERROR_INSUFFICIENT_SCOPE
const ERROR_INSUFFICIENT_SCOPE
Definition
scope.php:15
Bitrix\Rest\Engine\ActionFilter\Scope\getCurrentScope
getCurrentScope()
Definition
scope.php:46
Bitrix\Rest\Engine\ActionFilter\Scope\onBeforeAction
onBeforeAction(Event $event)
Definition
scope.php:25
Bitrix\Rest\Engine\ActionFilter\Scope\__construct
__construct(... $scopes)
Definition
scope.php:19
Bitrix\Rest\Engine\ActionFilter
Definition
authtype.php:3
modules
rest
lib
engine
actionfilter
scope.php
Создано системой
1.10.0