xel/psr7bridge 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

xel/psr7bridge

最新稳定版本:0.1.5

Composer 安装命令:

composer require xel/psr7bridge

包简介

README 文档

README


Swoole Psr7 Bridge

This library still not for production. The Idea of this library is to process copy Swoole Http response to psr 7 standart when needed and leverage this copy using Psr 17 factory. in response, it will have dynamic switching when the response content have the larger byte value, it will split and make it chunk to make it more light to send.

Explore the docs »

View Demo . Report Bug . Request Feature

Downloads Contributors Forks Stargazers Issues License

Getting Started

To get start with this library you need several prerequest

Prerequisites

  • ext-swoole => V 5.0.0
  • php => V 8.2

Installation

  1. Install with this command :
     composer require xel/psr7bridge

Usage

  1. In you server.php or in file which containt swoole server :
     <?php

use HttpSoft\Message\ServerRequestFactory;
use HttpSoft\Message\StreamFactory;
use HttpSoft\Message\UploadedFileFactory;
use HttpSoft\Message\ResponseFactory;
use Swoole\Http\Server;
use Swoole\Http\Request as SwooleRequest;
use Swoole\Http\Response as SwooleResponse;
use Xel\Psr7bridge\PsrFactory;


require __DIR__."/vendor/autoload.php";

$server = new Server("0.0.0.0", 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

$server->set([
    "worker_num" => 35,
    "dispatch_mode" => 1
]);

/***
 * In this sample using Psr7 and Psr17 Provided by HttpSoft.
 * u can u other library to utilize this
 */
$psr7RequestFactory =  new PsrFactory
(
    new ServerRequestFactory(),
    new StreamFactory(),
    new UploadedFileFactory(),

);

$psr7Response = new ResponseFactory();
$psr7Stream =  new StreamFactory();

$server->on("request" , function (SwooleRequest $request, SwooleResponse $response) use ($psr7RequestFactory,$psr7Response, $psr7Stream){

    // ? Connect Swoole http request with Psr 17 factory
    $psr7RequestFactory->connectRequest($request);

    // ? Sample data in stream
    $data = $psr7Stream->createStream("Hello Swoole");
    
    // ? create response and
    $manage = $psr7Response->createResponse();
    $manage =  $manage->withBody($data);
    $manage = $manage->withStatus(200);
    
    // ?  bridge it to psr7
    $psr7RequestFactory->connectResponse($manage, $response);
});

$server->start();

For more examples, please refer to the Documentation

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-01-20