1. Go to this page and download the library: Download xel/psr7bridge library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xel / psr7bridge example snippets
sh
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;
Factory(),
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();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.