swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.48k stars 3.16k forks source link

PHP Standerd Recommendation #1914

Closed azjezz closed 6 years ago

azjezz commented 6 years ago

is php swoole gonna implement psr-7, psr-15 any soon ?

so code like this can be possible :

<?php

use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

$handler = new class implements RequestHandlerInterface
{
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        // returns a ResponseInterface implementation.
    }
}

$middleware = new class implements MiddlewareInterface 
{
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface 
     {
         return $handler->handle($request);
     }
}

$server = new Server('127.0.0.1',80);

$server->handler($handler);

$server->middleware($middleware);

$server->start();

this would benefit both sides as swoole is gonna be compatibly with most frameworks and libraries while they gain performance boost from using it.

of course, Psr Interfaces are not implemented in php, so maybe swoole can create these interfaces, this won't break anything since Psr Interfaces are being loaded with composer auto-loader most of the time which mean since they already exist with swoole composer won't load the Psr interfaces files, but swoole would need to create all PSR-7 and PSR-15 interfaces.

twose commented 6 years ago

Swoole is only an underlying engine, You can see these: https://github.com/easy-swoole/easyswoole https://github.com/swoft-cloud/swoft https://github.com/swlib

most of the frameworks which based on swoole have already implemented PSR.

azjezz commented 6 years ago

@twose thanks for your response, i was asking if it gonna be implemented with the engine, if possible.

ghost commented 6 years ago

@azjezz this would swell the core. You can choose frameworks based on swoole which already implemented it. So, whats your question anymore? For me for example - i am not interested in using that.