RequestMethod
The method of a request, named so that nobody spells it.
What CkRequest::Bag()->Method() answers: the seven methods a
handler meets. Backed by the word as it travels on the wire, upper case, so RequestMethod::Post->value
is "POST" and RequestMethod::tryFrom($word) reads one back. Which part of the request is its
own follows from it: the query string on Get and Head, the body on the rest.
Members
| Member | Value | What the request carries |
|---|---|---|
Get |
GET |
A read: the parameters travel in the query string, and there is no body to read. |
Head |
HEAD |
A GET without the response body; read as a GET. |
Post |
POST |
A creation, a form post, a webhook: the data is in the body. |
Put |
PUT |
A full replacement: the data is in the body. |
Patch |
PATCH |
A partial change: the data is in the body. |
Delete |
DELETE |
A removal; a body is read when one is sent. |
Options |
OPTIONS |
A capabilities question, the browser's preflight among them; a body is read when one is sent. |
A live request may declare a method the enum does not name — WebDAV's PROPFIND, a cache's
PURGE. CkRequest reads such a request as one that carries a
body, and Bag()->Method() answers null for it.
Where it is used
CkRequest::Bag()->Method(), which answers it, read from
$_SERVER['REQUEST_METHOD'] in any case.
use SafeCoder\CommonKit\CkRequest;
use SafeCoder\CommonKit\Enums\RequestMethod;
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'multipart/form-data';
$_POST = ['id' => '7'];
CkRequest::Bag()->Method() === RequestMethod::Post; // -> true
CkRequest::Bag()->Method()?->value; // -> 'POST'
RequestMethod::tryFrom('PATCH') === RequestMethod::Patch; // -> true
RequestMethod::tryFrom('PROPFIND'); // -> null