1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
httpmethod.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Main\Engine\ActionFilter;
5
6
7use Bitrix\Main\Engine\Controller;
8use Bitrix\Main\Error;
9use Bitrix\Main\Event;
10use Bitrix\Main\EventResult;
11
12final 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}
addError(Error $error)
Определения base.php:80
onBeforeAction(Event $event)
Определения httpmethod.php:59
__construct(array $allowedMethods=array(self::METHOD_GET))
Определения httpmethod.php:33
Определения error.php:15
Определения event.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$event
Определения prolog_after.php:141