add solutions for chapter 10
This commit is contained in:
parent
d880aeb9a6
commit
e91a166816
18 changed files with 1872 additions and 0 deletions
23
implementation/10/config/container.php
Normal file
23
implementation/10/config/container.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use DI\ContainerBuilder;
|
||||
use Laminas\Diactoros\Response;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use Lubian\NoFramework\Service\Time\Clock;
|
||||
use Lubian\NoFramework\Service\Time\SystemClock;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
use function FastRoute\simpleDispatcher;
|
||||
|
||||
$builder = new ContainerBuilder;
|
||||
$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();
|
12
implementation/10/config/routes.php
Normal file
12
implementation/10/config/routes.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
use FastRoute\RouteCollector;
|
||||
use Lubian\NoFramework\Action\Hello;
|
||||
use Lubian\NoFramework\Action\Other;
|
||||
use Psr\Http\Message\ResponseInterface as RI;
|
||||
|
||||
return function (RouteCollector $r) {
|
||||
$r->addRoute('GET', '/hello[/{name}]', Hello::class);
|
||||
$r->addRoute('GET', '/other', [Other::class, 'handle']);
|
||||
$r->addRoute('GET', '/', fn (RI $r) => $r->withStatus(302)->withHeader('Location', '/hello'));
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue