drewlabs/psr7

v0.2.4 2024-08-16 01:10 UTC

This package is auto-updated.

Last update: 2024-09-16 01:17:25 UTC


README

本包提供了Psr7请求、响应和URI接口的实现。

安装

使用composer包管理器 [https://getcomposer.org.cn/download/].

composer require drewlabs/psr7

用法

  • 创建Psr7类

drewlabs/psr7包提供了一个Drewlabs\Psr7\Request类,用于创建Psr7请求

use Drewlabs\Psr7\Request;

// Instantiate the psr7 class
$request = new Request();

// Overriding the request method
$request = $request->withMethod('POST');

// Overriding request headers
$request = $request->withHeaders([
    // ...
]);
  • 创建Psr7响应接口

drewlabs/psr7包提供了一个Drewlabs\Psr7\Response类,用于创建Psr7响应

use Drewlabs\Psr7\Request;

// Instantiate the psr7 class
$response = new Response();

// Instantiate response with parameters
$response = new Response('', [/* Response headers */]);

// Overriding the response method
$response = $response->withStatusCode(404);

// Overriding response headers
$response = $response->withHeaders([
    // ...
]);
  • 创建Psr7 URI实例

drewlabs/psr7包提供了一个Drewlabs\Psr7\Uri类,用于创建Psr7 URI实例

$uri = Uri::new(/* URI string | or Null */);