shopexpress/request-response

ShopExpress 请求 - 响应

0.8.9 2021-12-13 13:59 UTC

README

请求实例化

$request = new \ShopExpress\RequestResponse\Request\Request('http://example.com/');

从查询字符串中检索单个输入

$request->query('test', 0);

检索所有查询字符串数据

$request->query();

从请求有效负载中检索单个输入

$request->request('test', 0);

检索所有请求有效负载数据

$request->request();

请求方法

$request->getMethod();

从请求中检索输入项

input 方法从整个请求有效负载(包括查询字符串)中检索值。对于 GET 和 HEAD 请求方法,不考虑请求体。

$request->input('test', 0);

确定输入值是否存在

如果您想确定请求中是否存在值且不为空,您可以使用 filled 方法。对于 GET 和 HEAD 请求方法,不考虑请求体。

$request->filled('test');

响应

响应实例化

$response = new \ShopExpress\RequestResponse\Response\Response(
    Request $request,
    200, 
    ['Content-Type' => 'text/html; charset=utf-8'], 
    'OK'
);

设置响应体

$response->setBody('test');

检索头值

$response->getHeader('Content-Type');

添加或替换头值

如果您想添加头值,请将最后一个参数传递为 true

$response->withHeader('Access-Control-Allow-Methods', 'PUT', true);
$response->withHeader('Access-Control-Allow-Origin', '*');