easyswoole/http-annotation

php stander lib

3.0.6 2023-02-04 05:58 UTC

README

安装

composer require easyswoole/http-annotation

注解规范

Example

use EasySwoole\Http\AbstractInterface\AbstractRouter;
use EasySwoole\Http\Dispatcher;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use EasySwoole\HttpAnnotation\Scanner;
use Swoole\Http\Server;

$nameSpace = 'EasySwoole\HttpAnnotation\Tests\ControllerExample';
$dispatcher = new Dispatcher();
$dispatcher->setNamespacePrefix($nameSpace);
$dispatcher->enableFakeRouter();
$dispatcher->setOnRouterCreate(function (AbstractRouter $router)use($nameSpace){
    Scanner::mappingRouter($router->getRouteCollector(),"tests/ControllerExample",$nameSpace);
});
$http = new Server("127.0.0.1", 9501);
$http->set([
    "worker_num"=>1
]);

$http->on("request", function ($request, $response) use($dispatcher){
    $request_psr = new Request($request);
    $response_psr = new Response($response);
    $dispatcher->dispatch($request_psr, $response_psr);
    $response_psr->__response();
});

$http->start();