Skip to content

Commit c2b4729

Browse files
authored
fix: remove duplicated documentation after bad merge (#1439)
1 parent 6551753 commit c2b4729

File tree

2 files changed

+5
-95
lines changed

2 files changed

+5
-95
lines changed

core/controllers.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,9 @@ use Symfony\Component\Routing\Annotation\Route;
369369
#[AsController]
370370
class CreateBookPublication extends AbstractController
371371
{
372-
private $bookPublishingHandler;
373-
374-
public function __construct(BookPublishingHandler $bookPublishingHandler)
375-
{
376-
$this->bookPublishingHandler = $bookPublishingHandler;
377-
}
372+
public function __construct(
373+
private BookPublishingHandler $bookPublishingHandler
374+
) {}
378375

379376
#[Route(
380377
name: 'book_post_publication',

core/operations.md

Lines changed: 2 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,6 @@ class Book
379379
App\Entity\Book:
380380
attributes:
381381
route_prefix: /library
382-
itemOperations:
383-
get: ~
384-
post_publication:
385-
route_name: book_post_publication
386-
book_post_discontinuation: ~
387382
```
388383
389384
```xml
@@ -395,13 +390,7 @@ App\Entity\Book:
395390
xsi:schemaLocation="https://api-platform.com/schema/metadata
396391
https://api-platform.com/schema/metadata/metadata-2.0.xsd">
397392
<resource class="App\Entity\Book">
398-
<itemOperations>
399-
<itemOperation name="get" />
400-
<itemOperation name="post_publication">
401-
<attribute name="route_name">book_post_publication</attribute>
402-
</itemOperation>
403-
<itemOperation name="book_post_discontinuation" />
404-
</itemOperations>
393+
<attribute name="route_prefix">/library</attribute>
405394
</resource>
406395
</resources>
407396
```
@@ -410,83 +399,7 @@ App\Entity\Book:
410399

411400
Alternatively, the more verbose attribute syntax can be used: `@ApiResource(attributes={"route_prefix"="/library"})`.
412401

413-
API Platform will automatically map this `post_publication` operation to the route `book_post_publication`. Let's create a custom action
414-
and its related route using annotations:
415-
416-
```php
417-
<?php
418-
// api/src/Controller/CreateBookPublication.php
419-
420-
namespace App\Controller;
421-
422-
use App\Entity\Book;
423-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
424-
use Symfony\Component\HttpKernel\Attribute\AsController;
425-
use Symfony\Component\Routing\Annotation\Route;
426-
427-
#[AsController]
428-
class CreateBookPublication extends AbstractController
429-
{
430-
public function __construct(
431-
private BookPublishingHandler $bookPublishingHandler
432-
) {}
433-
434-
#[Route(
435-
path: '/books/{id}/publication',
436-
name: 'book_post_publication',
437-
defaults: [
438-
'_api_resource_class' => Book::class,
439-
'_api_item_operation_name' => 'post_publication',
440-
],
441-
methods: ['POST'],
442-
)]
443-
public function __invoke(Book $data): Book
444-
{
445-
$this->bookPublishingHandler->handle($data);
446-
447-
return $data;
448-
}
449-
}
450-
```
451-
452-
It is mandatory to set `_api_resource_class` and `_api_item_operation_name` (or `_api_collection_operation_name` for a collection
453-
operation) in the parameters of the route (`defaults` key). It allows API Platform to work with the Symfony routing system.
454-
455-
Alternatively, you can also use a traditional Symfony controller and YAML or XML route declarations. The following example does
456-
the same thing as the previous example:
457-
458-
```php
459-
<?php
460-
// api/src/Controller/BookController.php
461-
462-
namespace App\Controller;
463-
464-
use App\Entity\Book;
465-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
466-
use Symfony\Component\HttpKernel\Attribute\AsController;
467-
468-
#[AsController]
469-
class BookController extends AbstractController
470-
{
471-
public function createPublication(Book $data, BookPublishingHandler $bookPublishingHandler): Book
472-
{
473-
return $bookPublishingHandler->handle($data);
474-
}
475-
}
476-
```
477-
478-
```yaml
479-
# api/config/routes.yaml
480-
book_post_publication:
481-
path: /books/{id}/publication
482-
methods: ['POST']
483-
defaults:
484-
_controller: App\Controller\BookController::createPublication
485-
_api_resource_class: App\Entity\Book
486-
_api_item_operation_name: post_publication
487-
```
488-
489-
## Expose a model without any routes
402+
## Expose a Model Without Any Routes
490403

491404
Sometimes, you may want to expose a model, but want it to be used through subrequests only, and never through item or collection operations.
492405
Because the OpenAPI standard requires at least one route to be exposed to make your models consumable, let's see how you can manage this kind

0 commit comments

Comments
 (0)