Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
scope.php
1
<?php
2
3
namespace
Bitrix\Main\Engine\ActionFilter
;
4
5
use
Bitrix\Main\ArgumentOutOfRangeException
;
6
use
Bitrix\Main\Engine\Controller
;
7
use
Bitrix\Main\Error
;
8
use
Bitrix\Main\Event
;
9
use
Bitrix\Main\EventResult
;
10
11
class
Scope
extends
Base
12
{
13
public
const
AJAX
= 0b00000001;
14
public
const
REST
= 0b00000010;
15
public
const
CLI
= 0b00000100;
16
public
const
ALL
= 0b00000111;
17
18
public
const
NOT_AJAX
= self::ALL & ~self
::AJAX
;
19
public
const
NOT_REST
= self::ALL & ~self
::REST
;
20
public
const
NOT_CLI
= self::ALL & ~self
::CLI
;
21
22
private
$scopes;
23
24
public
function
__construct
($scopes)
25
{
26
$this->scopes = $scopes;
27
parent::__construct();
28
}
29
30
public
function
onBeforeAction
(
Event
$event)
31
{
32
$scope = $this->
getCurrentScope
();
33
if
(($this->scopes & $scope) === $scope)
34
{
35
return
null
;
36
}
37
38
$this->
addError
(
new
Error
(
'Requested scope is invalid'
));
39
40
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
41
}
42
43
protected
function
getCurrentScope
()
44
{
45
switch
($this->
getAction
()->getController()->getScope())
46
{
47
case
Controller::SCOPE_AJAX
:
48
return
static::AJAX;
49
case
Controller::SCOPE_REST
:
50
return
static::REST;
51
case
Controller::SCOPE_CLI
:
52
return
static::CLI;
53
}
54
55
throw
new
ArgumentOutOfRangeException
(
'Scope is invalid'
);
56
}
57
}
Bitrix\Main\ArgumentOutOfRangeException
Definition
exception.php:67
Bitrix\Main\Engine\ActionFilter\Base
Definition
base.php:15
Bitrix\Main\Engine\ActionFilter\Base\addError
addError(Error $error)
Definition
base.php:80
Bitrix\Main\Engine\ActionFilter\Base\getAction
getAction()
Definition
base.php:48
Bitrix\Main\Engine\ActionFilter\Scope
Definition
scope.php:12
Bitrix\Main\Engine\ActionFilter\Scope\REST
const REST
Definition
scope.php:14
Bitrix\Main\Engine\ActionFilter\Scope\AJAX
const AJAX
Definition
scope.php:13
Bitrix\Main\Engine\ActionFilter\Scope\getCurrentScope
getCurrentScope()
Definition
scope.php:43
Bitrix\Main\Engine\ActionFilter\Scope\onBeforeAction
onBeforeAction(Event $event)
Definition
scope.php:30
Bitrix\Main\Engine\ActionFilter\Scope\NOT_AJAX
const NOT_AJAX
Definition
scope.php:18
Bitrix\Main\Engine\ActionFilter\Scope\ALL
const ALL
Definition
scope.php:16
Bitrix\Main\Engine\ActionFilter\Scope\__construct
__construct($scopes)
Definition
scope.php:24
Bitrix\Main\Engine\ActionFilter\Scope\NOT_REST
const NOT_REST
Definition
scope.php:19
Bitrix\Main\Engine\ActionFilter\Scope\CLI
const CLI
Definition
scope.php:15
Bitrix\Main\Engine\ActionFilter\Scope\NOT_CLI
const NOT_CLI
Definition
scope.php:20
Bitrix\Main\Engine\Controller
Definition
controller.php:32
Bitrix\Main\Engine\Controller\SCOPE_AJAX
const SCOPE_AJAX
Definition
controller.php:34
Bitrix\Main\Engine\Controller\SCOPE_CLI
const SCOPE_CLI
Definition
controller.php:35
Bitrix\Main\Engine\Controller\SCOPE_REST
const SCOPE_REST
Definition
controller.php:33
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Main\Engine\ActionFilter
Definition
authentication.php:4
modules
main
lib
engine
actionfilter
scope.php
Создано системой
1.10.0