Skip to content

Commit b473f4c

Browse files
committed
Issue #110: update book tutorial
Signed-off-by: horea <horea@rospace.com>
1 parent 9757b37 commit b473f4c

File tree

2 files changed

+46
-59
lines changed

2 files changed

+46
-59
lines changed

docs/book/v5/tutorials/create-book-module.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ class RoutesDelegator
654654

655655
$app->get(
656656
'/book/' . $uuid,
657-
Book::class,
657+
BookHandler::class,
658658
'book.show'
659659
);
660660

docs/book/v6/tutorials/create-book-module.md

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,26 @@ The below files structure is what we will have at the end of this tutorial and i
1818
│ │ ├── GetBookHandler.php
1919
│ │ └── PostBookHandler.php
2020
│ ├── InputFilter/
21+
│ │ ├── Input/
22+
│ │ │ ├── AuthorInput.php
23+
│ │ │ ├── NameInput.php
24+
│ │ │ └── ReleaseDateInput.php
2125
│ │ └── CreateBookInputFilter.php
2226
│ ├── Service/
2327
│ │ ├── BookService.php
2428
│ │ └── BookServiceInterface.php
2529
│ ├── ConfigProvider.php
2630
│ └── RoutesDelegator.php
27-
├── Core/
28-
│ └── src/
29-
│ └── Book/
30-
│ └── src/
31-
│ ├──Entity/
32-
│ │ └──Book.php
33-
│ ├──Repository/
34-
│ │ └──BookRepository.php
35-
│ └── ConfigProvider.php
36-
└── App/
37-
└──src/
38-
└── InputFilter/
39-
└── Input/
40-
├── AuthorInput.php
41-
├── NameInput.php
42-
└── ReleaseDateInput.php
31+
└── Core/
32+
└── src/
33+
└── Book/
34+
└── src/
35+
├──Entity/
36+
│ └──Book.php
37+
├──Repository/
38+
│ └──BookRepository.php
39+
└── ConfigProvider.php
40+
4341
```
4442

4543
* `src/Book/src/Collection/BookCollection.php` - a collection refers to a container for a group of related objects, typically used to manage sets of related entities fetched from a database
@@ -52,7 +50,7 @@ The below files structure is what we will have at the end of this tutorial and i
5250
* `src/Book/src/ConfigProvider.php` - is a class that provides configuration for various aspects of the framework or application
5351
* `src/Book/src/RoutesDelegator.php` - a routes delegator is a delegator factory responsible for configuring routing middleware based on routing configuration provided by the application
5452
* `src/Book/src/InputFilter/CreateBookInputFilter.php` - input filters and validators
55-
* `src/Core/src/App/src/InputFilter/Input/*` - input filters and validator configurations
53+
* `src/Book/src/InputFilter/Input/*` - input filters and validator configurations
5654

5755
## Creating and configuring the module
5856

@@ -180,57 +178,46 @@ In `src/Core/src/Book/src` we will create 1 PHP file: `ConfigProvider.php`. This
180178

181179
declare(strict_types=1);
182180

183-
namespace Api\Book;
181+
namespace Core\Book;
184182

185-
use Api\App\ConfigProvider as AppConfigProvider;
186-
use Api\App\Factory\HandlerDelegatorFactory;
187-
use Api\Book\Collection\BookCollection;
188-
use Api\Book\Handler\GetBookCollectionHandler;
189-
use Api\Book\Handler\GetBookHandler;
190-
use Api\Book\Handler\PostBookHandler;
191-
use Api\Book\Service\BookService;
192-
use Api\Book\Service\BookServiceInterface;
193-
use Core\Book\Entity\Book;
194-
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
195-
use Mezzio\Application;
196-
use Mezzio\Hal\Metadata\MetadataMap;
183+
use Core\Book\Repository\BookRepository;
184+
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
185+
use Dot\DependencyInjection\Factory\AttributedRepositoryFactory;
197186

198187
class ConfigProvider
199188
{
200189
public function __invoke(): array
201190
{
202191
return [
203192
'dependencies' => $this->getDependencies(),
204-
MetadataMap::class => $this->getHalConfig(),
193+
'doctrine' => $this->getDoctrineConfig(),
205194
];
206195
}
207196

208197
private function getDependencies(): array
209198
{
210199
return [
211-
'delegators' => [
212-
Application::class => [RoutesDelegator::class],
213-
PostBookHandler::class => [HandlerDelegatorFactory::class],
214-
GetBookHandler::class => [HandlerDelegatorFactory::class],
215-
GetBookCollectionHandler::class => [HandlerDelegatorFactory::class],
216-
],
217-
'factories' => [
218-
PostBookHandler::class => AttributedServiceFactory::class,
219-
GetBookHandler::class => AttributedServiceFactory::class,
220-
GetBookCollectionHandler::class => AttributedServiceFactory::class,
221-
BookService::class => AttributedServiceFactory::class,
222-
],
223-
'aliases' => [
224-
BookServiceInterface::class => BookService::class,
200+
'factories' => [
201+
BookRepository::class => AttributedRepositoryFactory::class,
225202
],
226203
];
227204
}
228205

229-
private function getHalConfig(): array
206+
private function getDoctrineConfig(): array
230207
{
231208
return [
232-
AppConfigProvider::getResource(Book::class, 'book::view-book'),
233-
AppConfigProvider::getCollection(BookCollection::class, 'book::list-books', 'books'),
209+
'driver' => [
210+
'orm_default' => [
211+
'drivers' => [
212+
'Core\Book\Entity' => 'BookEntities',
213+
],
214+
],
215+
'BookEntities' => [
216+
'class' => AttributeDriver::class,
217+
'cache' => 'array',
218+
'paths' => [__DIR__ . '/Entity'],
219+
],
220+
],
234221
];
235222
}
236223
}
@@ -468,14 +455,14 @@ class BookService implements BookServiceInterface
468455

469456
When creating or updating a book, we will need some validators, so we will create input filters that will be used to validate the data received in the request
470457

471-
* `src/App/src/InputFilter/Input/AuthorInput.php`
458+
* `src/Book/src/InputFilter/Input/AuthorInput.php`
472459

473460
```php
474461
<?php
475462

476463
declare(strict_types=1);
477464

478-
namespace Api\App\InputFilter\Input;
465+
namespace Api\Book\InputFilter\Input;
479466

480467
use Core\App\Message;
481468
use Laminas\Filter\StringTrim;
@@ -505,14 +492,14 @@ class AuthorInput extends Input
505492
}
506493
```
507494

508-
* `src/App/src/InputFilter/Input/NameInput.php`
495+
* `src/Book/src/InputFilter/Input/NameInput.php`
509496

510497
```php
511498
<?php
512499

513500
declare(strict_types=1);
514501

515-
namespace Api\App\InputFilter\Input;
502+
namespace Api\Book\InputFilter\Input;
516503

517504
use Core\App\Message;
518505
use Laminas\Filter\StringTrim;
@@ -542,14 +529,14 @@ class NameInput extends Input
542529
}
543530
```
544531

545-
* `src/App/src/InputFilter/Input/ReleaseDateInput.php`
532+
* `src/Book/src/InputFilter/Input/ReleaseDateInput.php`
546533

547534
```php
548535
<?php
549536

550537
declare(strict_types=1);
551538

552-
namespace Api\App\InputFilter\Input;
539+
namespace Api\Book\InputFilter\Input;
553540

554541
use Core\App\Message;
555542
use Laminas\Filter\StringTrim;
@@ -590,10 +577,10 @@ declare(strict_types=1);
590577

591578
namespace Api\Book\InputFilter;
592579

593-
use Api\App\InputFilter\Input\AuthorInput;
594-
use Api\App\InputFilter\Input\NameInput;
595-
use Api\App\InputFilter\Input\ReleaseDateInput;
596-
use Core\App\InputFilter\AbstractInputFilter;
580+
use Api\Book\InputFilter\Input\AuthorInput;
581+
use Api\Book\InputFilter\Input\NameInput;
582+
use Api\Book\InputFilter\Input\ReleaseDateInput;
583+
use Core\Book\InputFilter\AbstractInputFilter;
597584

598585
class CreateBookInputFilter extends AbstractInputFilter
599586
{

0 commit comments

Comments
 (0)