Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/razonyang/psr7-swoole

The PSR7 helpers for Swoole.
https://github.com/razonyang/psr7-swoole

psr-7 psr7 swoole

Last synced: 10 days ago
JSON representation

The PSR7 helpers for Swoole.

Lists

README

        

# Swoole + PSR7

[![Latest Stable Version](https://poser.pugx.org/razonyang/psr7-swoole/v/stable.png)](https://packagist.org/packages/razonyang/psr7-swoole)
[![Total Downloads](https://poser.pugx.org/razonyang/psr7-swoole/downloads.png)](https://packagist.org/packages/razonyang/psr7-swoole)
[![Build Status](https://github.com/razonyang/psr7-swoole/workflows/build/badge.svg)](https://github.com/razonyang/psr7-swoole/actions)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/razonyang/psr7-swoole/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/razonyang/psr7-swoole/?branch=main)
[![Code Coverage](https://scrutinizer-ci.com/g/razonyang/psr7-swoole/badges/coverage.png?b=main)](https://scrutinizer-ci.com/g/razonyang/psr7-swoole/?branch=main)
[![StyleCI](https://github.styleci.io/repos/537541555/shield?branch=main)](https://github.styleci.io/repos/537541555?branch=main)

The PSR-7 helpers for Swoole, the bridge of Swoole and PSR things, such as PSR-7 HTTP message, PSR-15 handlers and PSR-15 middlewares.
It allows to integrate Swoole with PSR-compatible frameworks to speed up your applications.

- Convert `Swoole\Http\Request` to `Psr\Http\Message\ServerRequestInterface`.
- Emit `Psr\Http\Message\ResponseInterface` to `Swoole\Http\Response`.

## Installation

```bash
composer require razonyang/psr7-swoole --prefer-dist
```

## Usage

```php
handle('/', function ($request, $response) use ($emitterFactory, $serverRequestFactory, $psr7Factory) {
$emitter = $emitterFactory->create($response);
$psrRequest = $serverRequestFactory->create($request);
$psrResponse = $psr7Factory
->createResponse(200)
->withBody(Stream::create($psrRequest->getUri()->getPath()));
$emitter->emit($psrResponse);
});

$server->start();
});
```