explain implementation of ad-hoc depencency container

This commit is contained in:
lubiana 2022-05-21 00:21:15 +02:00 committed by Andre Lubian
parent 988a532b78
commit 2c3901e9f9
3 changed files with 197 additions and 4 deletions

View file

@ -2,6 +2,7 @@
namespace Lubian\NoFramework\Action;
use Lubian\NoFramework\Service\Time\Clock;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
@ -9,7 +10,10 @@ use Psr\Http\Server\RequestHandlerInterface;
final class Hello implements RequestHandlerInterface
{
public function __construct(private readonly ResponseInterface $response, private readonly Clock $clock)
public function __construct(
private readonly ResponseInterface $response,
private readonly Clock $clock
)
{
}

View file

@ -59,7 +59,7 @@ try {
switch ($routeInfo[0]) {
case Dispatcher::FOUND:
$className = $routeInfo[1];
$handler = $container->get($className);
$handler = new $className($response);
assert($handler instanceof RequestHandlerInterface);
foreach ($routeInfo[2] as $attributeName => $attributeValue) {
$request = $request->withAttribute($attributeName, $attributeValue);