compwright/swoole-psr7-compat

This package is abandoned and no longer maintained. The author suggests using the openswoole/core package instead.

PSR compatibility adapters for Swoole

2.1.0 2022-08-02 00:59 UTC

This package is auto-updated.

Last update: 2023-01-02 16:26:18 UTC


README

Build Status Coverage Status

PSR compatibility adapters for Openswoole

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();