定制 thingston/psr7 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thingston/psr7

最新稳定版本:1.0.0

Composer 安装命令:

composer require thingston/psr7

包简介

Implementation of PSR-7 standard for representing HTTP messages as described in RFC 7230 and RFC 7231, and URIs for use with HTTP messages as described in RFC 3986.

README 文档

README

Implementation of PSR-7 standard for representing HTTP messages as described in RFC 7230 and RFC 7231, and URIs for use with HTTP messages as described in RFC 3986.

Requirements

  • PHP >=8.5
  • Composer

Installation

Install the package with Composer:

composer require thingston/psr7

Usage

Create a request

<?php

use Thingston\Psr7\Request;

$request = new Request(
    method: 'POST',
    uri: 'https://api.example.com/users?active=1',
    headers: [
        'Content-Type' => 'application/json',
        'Accept' => 'application/json',
    ],
);

$request = $request->withBody(new \Thingston\Psr7\Stream('{"name":"Ada"}'));

echo $request->getMethod();          // POST
echo $request->getRequestTarget();   // /users?active=1
echo $request->getHeaderLine('Host'); // api.example.com

Create a response

<?php

use Thingston\Psr7\Response;
use Thingston\Psr7\Stream;

$response = new Response(
    statusCode: 201,
    headers: ['Content-Type' => 'application/json'],
    body: new Stream('{"created":true}')
);

echo $response->getStatusCode();   // 201
echo $response->getReasonPhrase(); // Created

Work with URIs

<?php

use Thingston\Psr7\Uri;

$uri = (new Uri('https://example.com/base/path'))
    ->withQuery('page=2')
    ->withFragment('details');

echo (string) $uri; // https://example.com/base/path?page=2#details

Build a server request from PHP globals

<?php

use Thingston\Psr7\ServerRequest;

$request = ServerRequest::fromGlobals();

echo $request->getMethod();
echo (string) $request->getUri();
print_r($request->getQueryParams());
print_r($request->getUploadedFiles());

Uploaded files

<?php

use Thingston\Psr7\UploadedFile;

$file = new UploadedFile('/tmp/report.csv', 1234, UPLOAD_ERR_OK, 'report.csv', 'text/csv');
$file->moveTo(__DIR__ . '/storage/report.csv');

Notes

PSR-7 objects in this package are immutable. Methods such as withHeader(), withStatus(), withUri(), and withParsedBody() return a new instance instead of modifying the original object.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固