add solutions for chapter 9 and fix urltypos
This commit is contained in:
parent
0b1fa54d49
commit
6920ea390d
5 changed files with 17 additions and 19 deletions
2
implementation/09/composer.lock
generated
2
implementation/09/composer.lock
generated
|
@ -1462,5 +1462,5 @@
|
|||
"php": ">=8.1"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
"plugin-api-version": "2.2.0"
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use DI\ContainerBuilder;
|
||||
use FastRoute\Dispatcher;
|
||||
use Laminas\Diactoros\Response;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use Lubian\NoFramework\Service\Time\Clock;
|
||||
|
@ -12,12 +11,13 @@ use Psr\Http\Message\ServerRequestInterface;
|
|||
use function FastRoute\simpleDispatcher;
|
||||
|
||||
$builder = new ContainerBuilder;
|
||||
|
||||
$builder->addDefinitions([
|
||||
ServerRequestInterface::class => fn () => ServerRequestFactory::fromGlobals(),
|
||||
ResponseInterface::class => fn () => new Response,
|
||||
Dispatcher::class => fn () => simpleDispatcher(require __DIR__ . '/routes.php'),
|
||||
Clock::class => fn () => new SystemClock,
|
||||
]);
|
||||
$builder->addDefinitions(
|
||||
[
|
||||
ServerRequestInterface::class => fn () => ServerRequestFactory::fromGlobals(),
|
||||
ResponseInterface::class => fn () => new Response,
|
||||
FastRoute\Dispatcher::class => fn () => simpleDispatcher(require __DIR__ . '/routes.php'),
|
||||
Clock::class => fn () => new SystemClock,
|
||||
]
|
||||
);
|
||||
|
||||
return $builder->build();
|
||||
|
|
|
@ -11,7 +11,7 @@ final class Hello implements RequestHandlerInterface
|
|||
{
|
||||
public function __construct(
|
||||
private readonly ResponseInterface $response,
|
||||
private readonly Clock $clock
|
||||
private readonly Clock $clock,
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,8 @@ final class Hello implements RequestHandlerInterface
|
|||
$name = $request->getAttribute('name', 'Stranger');
|
||||
$body = $this->response->getBody();
|
||||
|
||||
$time = $this->clock->now()
|
||||
->format('H:i:s');
|
||||
|
||||
$body->write('Hello ' . $name . '!<br />');
|
||||
$body->write('The Time is: ' . $time);
|
||||
$body->write('The time is: ' . $this->clock->now()->format('H:i:s'));
|
||||
|
||||
return $this->response->withBody($body)
|
||||
->withStatus(200);
|
||||
|
|
|
@ -52,7 +52,6 @@ assert($request instanceof ServerRequestInterface);
|
|||
$dispatcher = $container->get(Dispatcher::class);
|
||||
assert($dispatcher instanceof Dispatcher);
|
||||
|
||||
|
||||
$routeInfo = $dispatcher->dispatch($request->getMethod(), $request->getUri() ->getPath(),);
|
||||
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue