Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
httpmethod.php
1
<?php
2
3
4
namespace
Bitrix\Main\Engine\ActionFilter
;
5
6
7
use
Bitrix\Main\Engine\Controller
;
8
use
Bitrix\Main\Error
;
9
use
Bitrix\Main\Event
;
10
use
Bitrix\Main\EventResult
;
11
12
final
class
HttpMethod
extends
Base
13
{
14
public
const
METHOD_GET
=
'GET'
;
15
public
const
METHOD_POST
=
'POST'
;
16
public
const
METHOD_PUT
=
'PUT'
;
17
public
const
METHOD_PATCH
=
'PATCH'
;
18
public
const
METHOD_DELETE
=
'DELETE'
;
19
public
const
METHOD_CONNECT
=
'CONNECT'
;
20
public
const
METHOD_OPTIONS
=
'OPTIONS'
;
21
public
const
METHOD_TRACE
=
'TRACE'
;
22
23
const
ERROR_INVALID_HTTP_METHOD
=
'invalid_http_method'
;
27
private
$allowedMethods;
28
33
public
function
__construct
(array $allowedMethods = array(self::METHOD_GET))
34
{
35
$this->allowedMethods = $allowedMethods;
36
parent::__construct();
37
}
38
43
public
function
listAllowedScopes
()
44
{
45
return
array(
46
Controller::SCOPE_AJAX
,
47
Controller::SCOPE_REST
,
48
);
49
}
50
54
public
function
containsPostMethod
()
55
{
56
return
in_array(self::METHOD_POST, $this->allowedMethods,
true
);
57
}
58
59
public
function
onBeforeAction
(
Event
$event)
60
{
61
$requestMethod = $this->action->getController()->getRequest()->getRequestMethod();
62
63
if
(!in_array($requestMethod, $this->allowedMethods,
true
))
64
{
65
$this->
addError
(
new
Error
(
66
'Wrong method for current action'
,
67
self::ERROR_INVALID_HTTP_METHOD
68
));
69
70
return
new
EventResult
(EventResult::ERROR,
null
,
null
, $this);
71
}
72
73
return
null
;
74
}
75
}
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\HttpMethod
Definition
httpmethod.php:13
Bitrix\Main\Engine\ActionFilter\HttpMethod\METHOD_PUT
const METHOD_PUT
Definition
httpmethod.php:16
Bitrix\Main\Engine\ActionFilter\HttpMethod\ERROR_INVALID_HTTP_METHOD
const ERROR_INVALID_HTTP_METHOD
Definition
httpmethod.php:23
Bitrix\Main\Engine\ActionFilter\HttpMethod\METHOD_POST
const METHOD_POST
Definition
httpmethod.php:15
Bitrix\Main\Engine\ActionFilter\HttpMethod\METHOD_OPTIONS
const METHOD_OPTIONS
Definition
httpmethod.php:20
Bitrix\Main\Engine\ActionFilter\HttpMethod\METHOD_DELETE
const METHOD_DELETE
Definition
httpmethod.php:18
Bitrix\Main\Engine\ActionFilter\HttpMethod\onBeforeAction
onBeforeAction(Event $event)
Definition
httpmethod.php:59
Bitrix\Main\Engine\ActionFilter\HttpMethod\containsPostMethod
containsPostMethod()
Definition
httpmethod.php:54
Bitrix\Main\Engine\ActionFilter\HttpMethod\__construct
__construct(array $allowedMethods=array(self::METHOD_GET))
Definition
httpmethod.php:33
Bitrix\Main\Engine\ActionFilter\HttpMethod\METHOD_GET
const METHOD_GET
Definition
httpmethod.php:14
Bitrix\Main\Engine\ActionFilter\HttpMethod\METHOD_PATCH
const METHOD_PATCH
Definition
httpmethod.php:17
Bitrix\Main\Engine\ActionFilter\HttpMethod\METHOD_TRACE
const METHOD_TRACE
Definition
httpmethod.php:21
Bitrix\Main\Engine\ActionFilter\HttpMethod\METHOD_CONNECT
const METHOD_CONNECT
Definition
httpmethod.php:19
Bitrix\Main\Engine\ActionFilter\HttpMethod\listAllowedScopes
listAllowedScopes()
Definition
httpmethod.php:43
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_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
httpmethod.php
Создано системой
1.10.0