Slide 25
Slide 25 text
#RAKUSMeetup
25
class PageAAction {
protected $Domain;
protected $Responder;
public function __construct(Domain $Domain, Responder
$Responder) {
$this->Domain = $Domain;
$this->Responder = $Responder;
}
public function __invoke(Request $request): Response {
return $this->Responder->response($request,
$this->Domain->get($request));
}
}
class PageAResponder {
protected $response;
protected $view;
public function __construct(Response $response, ViewFactory $view) {
$this->response = $response;
$this->view = $view;
}
public function response(Request $request, $data): Response {
$isEdit = $request->get('mode') === 'edit';
if ($isEdit) {
$sum = 0;
foreach ($request->get('count') as $count) {
$sum += $count;
}
}
$this->response->setContent(
$this->view->make('page_a', [
'isEdit' => ($isEdit) ? 'edit' : 'view',
'input' => $request->get('input'),
'count' => $sum,
])
);
return $this->response;
}
}
ビジネスロジック
PageAAction.php
PageAResponder.php