Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
httpmethod.php
1<?php
2
3
5
6
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(
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}
__construct(array $allowedMethods=array(self::METHOD_GET))