compwright/swoole-psr7-compat

PSR compatibility adapters for Swoole

2.0.0 2021-08-25 20:49 UTC

This package is auto-updated.

Last update: 2022-05-25 22:18:03 UTC


README

Build Status Coverage Status

PSR compatibility adapters for Swoole

Install

Via Composer

$ composer require compwright/swoole-psr7-compat

Usage

use Compwright\SwoolePsr7Compat\SwoolePsrRequestFactory;
use Compwright\SwoolePsr7Compat\SwoolePsrHandler;
use Nyholm\Psr7Server\ServerRequestCreator;

$serverRequestCreator = new ServerRequestCreator(
    // Pass in the factories here for your desired PSR-7 implementation
    new \Laminas\Diactoros\ServerRequestFactory(),
    new \Laminas\Diactoros\UriFactory(),
    new \Laminas\Diactoros\UploadedFileFactory(),
    new \Laminas\Diactoros\StreamFactory()
);
$requestFactory = new SwoolePsrRequestFactory($serverRequestCreator);
$handler = new SwoolePsrHandler($requestFactory);

$server = new Swoole\HTTP\Server('0.0.0.0', 9501);

// $app is any Psr\Http\Server\RequestHandlerInterface
$server->on('request', $handler($app));

$server->start();