1.1.4. Method

The Request $method property is a Sapien\Request\Method instance derived from the $server values.

The Method $name property is a readonly string.

// returns the derived method value
$requestMethod = $request->method->name;

// the method object is stringable:
assert($request->method->name === (string) $request->method);

The $name value is computed from the Request $server['REQUEST_METHOD'] element, or the Request $server['HTTP_X_HTTP_METHOD_OVERRIDE'] element, as appropriate.

In addition, the Method object has an is() method for checking the method name:

$isPost = $request->method->is('post');

You can override the default method value with a custom one via the Request constructor ...

$request = new Request(
    method: 'delete',
);

... or you can provide a Method object of your own construction:

$request = new Request(
    method: new Request\Method('delete'),
);