Action-Domain-Responder pattern implementation
More info here: 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 is licensed under the MIT License - see the LICENSE
file for details.