mrjulio / rapture-adr
Rapture ADR 组件
v1.0.2
2017-11-18 19:08 UTC
Requires
- php: >=7.0.4
This package is not auto-updated.
Last update: 2024-09-21 16:09:15 UTC
README
实现 Action-Domain-Responder 模式
更多信息请见此处: https://github.com/pmjones/adr
要求
- PHP v7.0
- php-json
安装
composer require mrjulio/rapture-adr
快速开始
# action namespace Demo\Action\User; class View extends Action { public function __invoke():array { $userId = $this->request()->getAttribute('id'); $user = \Demo\Domain\Model\UserQuery::create() ->filterById($userId) ->findOne(); if (!$user) { throw new HttpNotFoundException('User not found'); } return [ 'user' => $user ]; } } # Responder namespace Demo\Responder\User; class View extends Responder { // demo public function preInvoke(array $data) { $this->template = new Template($this->getTemplateName(), $data); } // demo public function __invoke(array $data) { $stream = new Stream(fopen('php://memory', 'r+')); $stream->write($this->template->render()); $this->response->withBody($stream)->send(); } } # Dispatcher (new Dispatcher('Demo', $router))->dispatch($request, $response);
关于
作者
Iulian N. rapture@iuliann.ro
鸣谢
许可证
Rapture PHP ADR 依据 MIT 许可证授权 - 详细信息请参阅 LICENSE
文件。