1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
scope.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Engine\ActionFilter;
4
5use Bitrix\Main\ArgumentOutOfRangeException;
6use Bitrix\Main\Engine\Controller;
7use Bitrix\Main\Error;
8use Bitrix\Main\Event;
9use Bitrix\Main\EventResult;
10
11class 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}
addError(Error $error)
Определения base.php:80
onBeforeAction(Event $event)
Определения scope.php:30
__construct($scopes)
Определения scope.php:24
Определения error.php:15
Определения event.php:5
$event
Определения prolog_after.php:141