Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
scope.php
1<?php
2
4
8
13class 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}