Skip to content

Commit 50edabe

Browse files
committed
Split Book/BookProvider/BookProcessor into separate files for PSR-4 autoloading
1 parent 231a2c6 commit 50edabe

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

core/bootstrap.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ Create the following file structure:
3939
├── bootstrap.php
4040
├── composer.json
4141
└── src/
42-
└── Book.php
42+
├── Book.php
43+
├── BookProcessor.php
44+
└── BookProvider.php
4345
```
4446

4547
Create `src/Book.php`:
@@ -50,17 +52,25 @@ Create `src/Book.php`:
5052
namespace App;
5153

5254
use ApiPlatform\Metadata\ApiResource;
53-
use ApiPlatform\Metadata\CollectionOperationInterface;
54-
use ApiPlatform\Metadata\Operation;
55-
use ApiPlatform\State\ProcessorInterface;
56-
use ApiPlatform\State\ProviderInterface;
5755

5856
#[ApiResource(provider: BookProvider::class, processor: BookProcessor::class)]
5957
class Book
6058
{
6159
public int $id;
6260
public string $title = '';
6361
}
62+
```
63+
64+
Create `src/BookProvider.php`:
65+
66+
```php
67+
<?php
68+
69+
namespace App;
70+
71+
use ApiPlatform\Metadata\CollectionOperationInterface;
72+
use ApiPlatform\Metadata\Operation;
73+
use ApiPlatform\State\ProviderInterface;
6474

6575
class BookProvider implements ProviderInterface
6676
{
@@ -84,6 +94,17 @@ class BookProvider implements ProviderInterface
8494
return $book;
8595
}
8696
}
97+
```
98+
99+
Create `src/BookProcessor.php`:
100+
101+
```php
102+
<?php
103+
104+
namespace App;
105+
106+
use ApiPlatform\Metadata\Operation;
107+
use ApiPlatform\State\ProcessorInterface;
87108

88109
class BookProcessor implements ProcessorInterface
89110
{

0 commit comments

Comments
 (0)