File tree Expand file tree Collapse file tree 5 files changed +74
-5
lines changed
Expand file tree Collapse file tree 5 files changed +74
-5
lines changed Original file line number Diff line number Diff line change 2020 },
2121 "require" : {
2222 "php" : " ^7.4" ,
23- "fig/http-message-util" : " ^1.1" ,
2423 "httpsoft/http-stream" : " ^1.0" ,
2524 "httpsoft/http-uploaded-file" : " ^1.0" ,
2625 "httpsoft/http-uri" : " ^1.0"
Original file line number Diff line number Diff line change 44
55namespace HttpSoft \Request ;
66
7- use Fig \Http \Message \RequestMethodInterface ;
87use HttpSoft \Uri \UriData ;
98use Psr \Http \Message \RequestInterface ;
109use Psr \Http \Message \StreamInterface ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace HttpSoft \Request ;
6+
7+ interface RequestMethodInterface
8+ {
9+ /**
10+ * @link https://tools.ietf.org/html/rfc7231#section-4.3.1
11+ */
12+ public const METHOD_GET = 'GET ' ;
13+
14+ /**
15+ * @link https://tools.ietf.org/html/rfc7231#section-4.3.2
16+ */
17+ public const METHOD_HEAD = 'HEAD ' ;
18+
19+ /**
20+ * @link https://tools.ietf.org/html/rfc7231#section-4.3.3
21+ */
22+ public const METHOD_POST = 'POST ' ;
23+
24+ /**
25+ * @link https://tools.ietf.org/html/rfc7231#section-4.3.4
26+ */
27+ public const METHOD_PUT = 'PUT ' ;
28+
29+ /**
30+ * @link https://tools.ietf.org/html/rfc5789#section-2
31+ */
32+ public const METHOD_PATCH = 'PATCH ' ;
33+
34+ /**
35+ * @link https://tools.ietf.org/html/rfc7231#section-4.3.5
36+ */
37+ public const METHOD_DELETE = 'DELETE ' ;
38+
39+ /**
40+ * @link https://tools.ietf.org/html/rfc7231#section-4.3.6
41+ */
42+ public const METHOD_CONNECT = 'CONNECT ' ;
43+
44+ /**
45+ * @link https://tools.ietf.org/html/rfc7231#section-4.3.7
46+ */
47+ public const METHOD_OPTIONS = 'OPTIONS ' ;
48+
49+ /**
50+ * @link https://tools.ietf.org/html/rfc7231#section-4.3.8
51+ */
52+ public const METHOD_TRACE = 'TRACE ' ;
53+
54+ /**
55+ * Array/List of all defined methods.
56+ */
57+ public const METHODS = [
58+ self ::METHOD_GET ,
59+ self ::METHOD_HEAD ,
60+ self ::METHOD_POST ,
61+ self ::METHOD_PUT ,
62+ self ::METHOD_PATCH ,
63+ self ::METHOD_DELETE ,
64+ self ::METHOD_CONNECT ,
65+ self ::METHOD_OPTIONS ,
66+ self ::METHOD_TRACE ,
67+ ];
68+ }
Original file line number Diff line number Diff line change 44
55namespace HttpSoft \Request ;
66
7- use Fig \Http \Message \RequestMethodInterface ;
87use HttpSoft \Stream \MessageTrait ;
98use HttpSoft \Stream \StreamFactory ;
109use HttpSoft \Uri \UriData ;
1615
1716use function gettype ;
1817use function get_class ;
18+ use function in_array ;
1919use function is_object ;
2020use function is_string ;
2121use function preg_match ;
2222use function sprintf ;
23+ use function strtoupper ;
2324
2425/**
2526 * Trait implementing the methods defined in `Psr\Http\Message\RequestInterface`.
@@ -249,7 +250,10 @@ private function init(
249250 */
250251 private function setMethod (string $ method ): void
251252 {
252- if (!preg_match ('/^[!#$%& \'*+.^_`|~0-9a-z-]+$/i ' , $ method )) {
253+ if (
254+ !in_array (strtoupper ($ method ), RequestMethodInterface::METHODS )
255+ && !preg_match ('/^[!#$%& \'*+.^_`|~0-9a-z-]+$/i ' , $ method )
256+ ) {
253257 throw new InvalidArgumentException (sprintf ('`%s` is not valid HTTP method. ' , $ method ));
254258 }
255259
Original file line number Diff line number Diff line change 44
55namespace HttpSoft \Request ;
66
7- use Fig \Http \Message \RequestMethodInterface ;
87use HttpSoft \Uri \UriData ;
98use InvalidArgumentException ;
109use Psr \Http \Message \ServerRequestInterface ;
You can’t perform that action at this time.
0 commit comments