explain implementation of ad-hoc depencency container
This commit is contained in:
parent
988a532b78
commit
2c3901e9f9
3 changed files with 197 additions and 4 deletions
|
@ -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
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue