add chapter 12 solutions
This commit is contained in:
parent
05f444152e
commit
0cd0b9def0
23 changed files with 1998 additions and 0 deletions
31
implementation/12/src/Action/Hello.php
Normal file
31
implementation/12/src/Action/Hello.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Lubian\NoFramework\Action;
|
||||
|
||||
use Lubian\NoFramework\Service\Time\Clock;
|
||||
use Lubian\NoFramework\Template\Renderer;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
final class Hello
|
||||
{
|
||||
public function __invoke(
|
||||
ResponseInterface $response,
|
||||
Clock $clock,
|
||||
Renderer $renderer,
|
||||
string $name = 'Stranger',
|
||||
): ResponseInterface {
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'time' => $clock->now()
|
||||
->format('H:i:s'),
|
||||
];
|
||||
|
||||
$content = $renderer->render('hello', $data,);
|
||||
|
||||
$body = $response->getBody();
|
||||
$body->write($content);
|
||||
|
||||
return $response->withBody($body)
|
||||
->withStatus(200);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue