charm/dispatcher
Composer 安装命令:
composer require charm/dispatcher
包简介
Creates PSR-7 Server Server Requests for PSR-15 Server Request Handlers and Middlewares from a web server, ReactPHP, Swoole or the command line.
README 文档
README
Create an application that implements Psr\Http\Server\RequestHandlerInterface, and run it:
<?php
use Psr\Http\Server\RequestHandlerInterface;
use function Charm\serve;
class HelloWorldApp implements RequestHandlerInterface {
/**
* Responds with "Hello World from /whatever/path"
*/
public function handle(ServerRequestInterface $request): ResponseInterface {
return $this->createResponse(200)->withBody($this->createStream("Hello World from ".$request->getRequestTarget()));
}
}
// Serve via HTTP or command line
serve(new MyApp());
Now you can access your application via the web and from the command line:
# php myapp.php
Hello World from /
# php myapp.php users 123
Hello World from /users/123
# php myapp.php users --email "you@example.com"
Hello World from /users?email=you@example.com
# curl https://myserver.php/users?email=you@example.com
Hello World from /users?email=you@example.com
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-12