add chapter 12 solutions

This commit is contained in:
lubiana 2022-05-31 17:49:17 +02:00
parent 05f444152e
commit 0cd0b9def0
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
23 changed files with 1998 additions and 0 deletions

View 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);
}
}

View file

@ -0,0 +1,24 @@
<?php declare(strict_types=1);
namespace Lubian\NoFramework\Action;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
final class Other implements RequestHandlerInterface
{
public function __construct(private readonly ResponseInterface $response)
{
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
$body = $this->response->getBody();
$body->write('This works too!');
return $this->response->withBody($body)
->withStatus(200);
}
}