diff --git a/09-dependency-injector.md b/09-dependency-injector.md index 14652ff..793fb06 100644 --- a/09-dependency-injector.md +++ b/09-dependency-injector.md @@ -16,7 +16,6 @@ we can later configure and switch our implementation. We need a new 'Service\Time' namespace, so lets first create the folder in our 'src' directory 'src/Service/Time'. There we place a Clock.php interface and a SystemClock.php implementation: - The Clock.php interface: ```php =8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/implementation/09/config/container.php b/implementation/09/config/container.php index ceb20dc..84e7386 100644 --- a/implementation/09/config/container.php +++ b/implementation/09/config/container.php @@ -1,7 +1,6 @@ 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(); diff --git a/implementation/09/src/Action/Hello.php b/implementation/09/src/Action/Hello.php index ec2e00c..012f1df 100644 --- a/implementation/09/src/Action/Hello.php +++ b/implementation/09/src/Action/Hello.php @@ -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 . '!
'); - $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); diff --git a/implementation/09/src/Bootstrap.php b/implementation/09/src/Bootstrap.php index 023c8c0..c5237b8 100644 --- a/implementation/09/src/Bootstrap.php +++ b/implementation/09/src/Bootstrap.php @@ -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 {