Skip to content

Commit 4b5766e

Browse files
committed
Automated deployment: Fri May 9 20:13:19 UTC 2025 0.3.5
1 parent cb3f77b commit 4b5766e

4 files changed

Lines changed: 79 additions & 190 deletions

File tree

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,5 +1143,5 @@ <h5 class="modal-title">Search</h5>
11431143

11441144
<!--
11451145
MkDocs version : 1.6.1
1146-
Build Date UTC : 2025-05-09 09:24:30.086316+00:00
1146+
Build Date UTC : 2025-05-09 20:13:18.765622+00:00
11471147
-->

search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

v5/tutorials/create-book-module/index.html

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ <h2 id="file-creation-and-contents">File creation and contents</h2>
13741374
], true);
13751375

13761376
$this-&gt;add($nameInput);</code></pre>
1377-
<p>Now it's time to create the handler.</p>
1377+
<p>Now it's time to create the handlers for the book entity and book collection.</p>
13781378
<ul>
13791379
<li><code>src/Book/src/Handler/BookHandler.php</code></li>
13801380
</ul>
@@ -1394,19 +1394,18 @@ <h2 id="file-creation-and-contents">File creation and contents</h2>
13941394
use Psr\Http\Message\ResponseInterface;
13951395
use Psr\Http\Message\ServerRequestInterface;
13961396
use Psr\Http\Server\RequestHandlerInterface;
1397-
use Dot\DependencyInjection\Attribute\Inject;
13981397

13991398
class BookHandler extends AbstractHandler implements RequestHandlerInterface
14001399
{
14011400
#[Inject(
14021401
BookServiceInterface::class,
1403-
"config"
1402+
"config",
14041403
HalResponseFactory::class,
14051404
ResourceGenerator::class,
14061405
)]
14071406
public function __construct(
14081407
protected BookServiceInterface $bookService,
1409-
protected array $config
1408+
protected array $config,
14101409
protected ?HalResponseFactory $responseFactory = null,
14111410
protected ?ResourceGenerator $resourceGenerator = null,
14121411
) {
@@ -1441,16 +1440,63 @@ <h2 id="file-creation-and-contents">File creation and contents</h2>
14411440

14421441
return $this-&gt;createResponse($request, $book);
14431442
}
1444-
}
1445-
</code></pre>
1443+
}</code></pre>
1444+
<ul>
1445+
<li><code>src/Book/src/Handler/BookCollectionHandler.php</code></li>
1446+
</ul>
1447+
<pre class="highlight"><code class="language-php">&lt;?php
1448+
1449+
declare(strict_types=1);
1450+
1451+
namespace Api\Book\Handler;
1452+
1453+
use Api\App\Exception\BadRequestException;
1454+
use Api\App\Handler\AbstractHandler;
1455+
use Api\Book\Service\BookServiceInterface;
1456+
use Dot\DependencyInjection\Attribute\Inject;
1457+
use Mezzio\Hal\HalResponseFactory;
1458+
use Mezzio\Hal\ResourceGenerator;
1459+
use Psr\Http\Message\ResponseInterface;
1460+
use Psr\Http\Message\ServerRequestInterface;
1461+
1462+
class BookCollectionHandler extends AbstractHandler
1463+
{
1464+
#[Inject(
1465+
BookServiceInterface::class,
1466+
"config",
1467+
HalResponseFactory::class,
1468+
ResourceGenerator::class,
1469+
)]
1470+
public function __construct(
1471+
protected BookServiceInterface $bookService,
1472+
protected array $config,
1473+
protected ?HalResponseFactory $responseFactory = null,
1474+
protected ?ResourceGenerator $resourceGenerator = null,
1475+
) {
1476+
}
1477+
1478+
/**
1479+
* @throws BadRequestException
1480+
*/
1481+
public function get(ServerRequestInterface $request): ResponseInterface
1482+
{
1483+
return $this-&gt;createResponse($request, $this-&gt;bookService-&gt;getBooks(
1484+
$request-&gt;getQueryParams()
1485+
));
1486+
}
1487+
}</code></pre>
14461488
<p>After we have the handler, we need to register some routes in the <code>RoutesDelegator</code>, the same we created when we registered the module.</p>
14471489
<ul>
14481490
<li><code>src/Book/src/RoutesDelegator.php</code></li>
14491491
</ul>
14501492
<pre class="highlight"><code class="language-php">&lt;?php
14511493

1494+
declare(strict_types=1);
1495+
14521496
namespace Api\Book;
14531497

1498+
use Api\Book\Collection\BookCollection;
1499+
use Api\Book\Handler\BookCollectionHandler;
14541500
use Api\Book\Handler\BookHandler;
14551501
use Mezzio\Application;
14561502
use Psr\Container\ContainerInterface;
@@ -1466,13 +1512,13 @@ <h2 id="file-creation-and-contents">File creation and contents</h2>
14661512

14671513
$app-&gt;get(
14681514
'/books',
1469-
BookHandler::class,
1515+
BookCollectionHandler::class,
14701516
'books.list'
14711517
);
14721518

14731519
$app-&gt;get(
1474-
'/book/'.$uuid,
1475-
BookHandler::class,
1520+
'/book/' . $uuid,
1521+
BookCollection::class,
14761522
'book.show'
14771523
);
14781524

@@ -1535,6 +1581,7 @@ <h2 id="file-creation-and-contents">File creation and contents</h2>
15351581
BookHandler::class =&gt; AttributedServiceFactory::class,
15361582
BookService::class =&gt; AttributedServiceFactory::class,
15371583
BookRepository::class =&gt; AttributedRepositoryFactory::class,
1584+
BookCollectionHandler::class =&gt; AttributedServiceFactory::class,
15381585
],
15391586
'aliases' =&gt; [
15401587
BookServiceInterface::class =&gt; BookService::class,

0 commit comments

Comments
 (0)