andrewbreksa / slim-action-helpers
一组类,使Slim 3更容易使用
1.0.1
2019-01-30 07:22 UTC
Requires
- php: ^7.1
- ext-json: *
- nilportugues/api-problems: ^1.2
- projek-xyz/slim-plates: ^0.2.2
- psr/container: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- mockery/mockery: ^1.2
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-08-29 04:54:39 UTC
README
快速且简单的辅助类,用于RAD slim 3开发,完全支持__invoke
Slim 3中间件和可调用范式。
安装
composer require andrewbreksa/slim-action-helpers
示例
动作
<?php namespace AndrewBreksa\SlimActionHelpers\Example\Actions; use AndrewBreksa\SlimActionHelpers\AbstractAction; class ExampleAction extends AbstractAction { public function act() { // do some magic here return $this->json([ 'entity' => [ 'email' => 'andrew@andrewbreksa.com', ] ], 201); } } $app->post('/emails', \AndrewBreksa\SlimActionHelpers\Example\Actions\ExampleAction::class);
中间件
<?php namespace AndrewBreksa\SlimActionHelpers\Example\Middleware; use AndrewBreksa\SlimActionHelpers\AbstractMiddleware; use Psr\Log\LoggerInterface; class RequestLoggingMiddleware extends AbstractMiddleware { /** * Here, if a ResponseInterface is returned, the stack is ejected from, otherwise we continue on and automaically * call $next * @return mixed|void|null */ public function act() { $this->getContainer()->get(LoggerInterface::class)->debug('request', [ 'method' => $this->getRequest()->getMethod(), 'uri' => $this->getRequest()->getUri()->getPath(), 'query' => $this->getRequest()->getQueryParams(), 'headers' => $this->getRequest()->getHeaders() ]); } } $app->add(\AndrewBreksa\SlimActionHelpers\Example\Middleware\RequestLoggingMiddleware::class);
文档
最终我可能会添加非常详细的文档,在此之前请阅读非常简单的源代码。实际上只有4个文件。