matthiasmullie / php-api
一个用于创建PHP API的简洁框架
1.0.0
2017-12-08 21:36 UTC
Requires
- php: ^7.0
- guzzlehttp/guzzle: ^6.2
- guzzlehttp/psr7: ^1.3
- league/route: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.0
- phpunit/phpunit: ~6.0
- symfony/yaml: ^3.2|^4.0
Suggests
- symfony/yaml: Needed to support routes in YAML format
This package is auto-updated.
Last update: 2024-08-25 22:29:46 UTC
README
示例用法
设置非常简单。
你需要一个路由配置
test: method: [GET, POST] path: / handler: MatthiasMullie\ApiExample\ExampleController
几行代码用于启动,在所有请求结束的文件中
$routes = new MatthiasMullie\Api\Routes\Providers\YamlRouteProvider(__DIR__.'/../config/routes.yml'); $handler = new MatthiasMullie\Api\RequestHandler($routes); $response = $handler->route(GuzzleHttp\Psr7\ServerRequest::fromGlobals()); $handler->output($response);
或者查看控制器
namespace MatthiasMullie\ApiExample; class ExampleController implements MatthiasMullie\Api\Controllers\JsonController { public function __invoke(Psr\Http\Message\ServerRequestInterface $request, ResponseInterface $response, array $args) { // hey there, I can process your request! return [ 'status_code' => 200, 'hello' => 'world', ]; } }
或者查看matthiasmullie/php-api-example中的完全相同的示例。
安装
如果你使用Composer来管理项目的依赖项,只需在composer.json文件中添加对matthiasmullie/php-api的依赖即可
composer require matthiasmullie/php-api
尽管推荐使用Composer,但实际上你可以以任何方式包含这些文件。
许可证
php-api遵循MIT许可证。