Skip to content

Commit 5717224

Browse files
committed
docs(controllers): move from core to symfony and update
1 parent 78d3384 commit 5717224

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

core/extending.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ Those extensions points are taken into account both by the REST and [GraphQL](gr
77
The following tables summarizes which extension point to use depending on what you want to do:
88

99
| Extension Point | Usage |
10-
| ---------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
10+
|------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1111
| [State Providers](state-providers.md) | adapters for custom persistence layers, virtual fields, custom hydration |
1212
| [Denormalizers](serialization.md) | post-process objects created from the payload sent in the HTTP request body |
13-
| [Voters](security.md#hooking-custom-permission-checks-using-voters) | custom authorization logic |
13+
| [Symfony Voters](../symfony/security.md#hooking-custom-permission-checks-using-voters) | custom authorization logic |
14+
| [Laravel Policies](../laravel/security.md#policies) | custom authorization logic |
1415
| [Validation constraints](validation.md) | custom validation logic |
1516
| [State Processors](state-processors) | custom business logic and computations to trigger before or after persistence (ex: mail, call to an external API...) |
1617
| [Normalizers](serialization.md#decorating-a-serializer-and-adding-extra-data) | customize the resource sent to the client (add fields in JSON documents, encode codes, dates...) |
@@ -22,16 +23,16 @@ The following tables summarizes which extension point to use depending on what y
2223

2324
## Doctrine Specific Extension Points
2425

25-
| Extension Point | Usage |
26-
| ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
27-
| [Extensions](extensions.md) | Access to the query builder to change the DQL query |
28-
| [Filters](filters.md#doctrine-orm-and-mongodb-odm-filters) | Add filters documentations (OpenAPI, GraphQL, Hydra) and automatically apply them to the DQL query |
26+
| Extension Point | Usage |
27+
|--------------------------------|----------------------------------------------------------------------------------------------------|
28+
| [Extensions](extensions.md) | Access to the query builder to change the DQL query |
29+
| [Filters](doctrine-filters.md) | Add filters documentations (OpenAPI, GraphQL, Hydra) and automatically apply them to the DQL query |
2930

3031
## Leveraging the Built-in Infrastructure Using Composition
3132

3233
While most API Platform classes are marked as `final`, built-in services are straightforward to reuse and customize [using composition](https://en.wikipedia.org/wiki/Composition_over_inheritance).
3334

34-
For instance, if you want to send a mail after a resource has been persisted, but still want to benefit from the native Doctrine ORM [state processor](state-processors.md), use [the decorator design pattern](https://en.wikipedia.org/wiki/Decorator_pattern#PHP) to wrap the native state processor in your own class sending the mail, as demonstrated in [this example](state-processors.md#decorating-the-built-in-state-processors).
35+
For instance, if you want to send a mail after a resource has been persisted, but still want to benefit from the native Doctrine ORM [state processor](state-processors.md), use [the decorator design pattern](https://en.wikipedia.org/wiki/Decorator_pattern#PHP) to wrap the native state processor in your own class sending the mail, as demonstrated in [this example](../core/state-processors.md#creating-a-custom-state-processor).
3536

3637
To replace existing API Platform services with your decorators, [check out how to decorate services](https://symfony.com/doc/current/service_container/service_decoration.html).
3738

outline.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ chapters:
1515
- user
1616
- jwt
1717
- file-upload
18+
- controllers
1819
- title: "API Platform for Laravel"
1920
path: laravel
2021
items:
@@ -64,7 +65,6 @@ chapters:
6465
- identifiers
6566
- mongodb
6667
- elasticsearch
67-
- controllers
6868
- events
6969
- jwt
7070
- form-data

core/controllers.md renamed to symfony/controllers.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Creating Custom Operations and Controllers
1+
# Creating Custom Operations and Symfony Controllers
22

3-
Note: using custom controllers with API Platform is **discouraged**. Also, GraphQL is **not supported**.
4-
[For most use cases, better extension points, working both with REST and GraphQL, are available](design.md).
3+
> [!NOTE]
4+
> Using custom Symfony controllers with API Platform is **discouraged**. Also, GraphQL is **not supported**.
5+
> [For most use cases, better extension points, working both with REST and GraphQL, are available](../core/design.md).
6+
> We recommend to use [System providers and processors](../core/extending.md#system-providers-and-processors) to extend API Platform internals.
57
68
API Platform can leverage the Symfony routing system to register custom operations related to custom controllers. Such custom
79
controllers can be any valid [Symfony controller](https://symfony.com/doc/current/controller.html), including standard
8-
Symfony controllers extending the [`Symfony\Bundle\FrameworkBundle\Controller\AbstractController`](http://api.symfony.com/4.1/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.html)
10+
Symfony controllers extending the [`Symfony\Bundle\FrameworkBundle\Controller\AbstractController`](https://symfony.com/doc/current/controller.html#the-base-controller-class-services)
911
helper class.
1012

1113
To enable this feature use `use_symfony_listeners: true` in your `api_platform` configuration file:
@@ -39,7 +41,7 @@ If your resource has any identifier, this operation will look like `/books/{id}`
3941
Those routes are not exposed from any documentation (for instance OpenAPI), but are anyway declared on the Symfony routing and always return a HTTP 404.
4042

4143
If you create a custom operation, you will probably want to properly document it.
42-
See the [OpenAPI](openapi.md) part of the documentation to do so.
44+
See the [OpenAPI](../core/openapi.md) part of the documentation to do so.
4345

4446
First, let's create your custom operation:
4547

@@ -90,7 +92,7 @@ you need and it will be autowired too.
9092
The `__invoke` method of the action is called when the matching route is hit. It can return either an instance of
9193
`Symfony\Component\HttpFoundation\Response` (that will be displayed to the client immediately by the Symfony kernel) or,
9294
like in this example, an instance of an entity mapped as a resource (or a collection of instances for collection operations).
93-
In this case, the entity will pass through [all built-in event listeners](events.md#built-in-event-listeners) of API Platform. It will be
95+
In this case, the entity will pass through [all built-in event listeners](../core/events.md#built-in-event-listeners) of API Platform. It will be
9496
automatically validated, persisted and serialized in JSON-LD. Then the Symfony kernel will send the resulting document to
9597
the client.
9698

@@ -165,7 +167,7 @@ Complex use cases may lead you to create multiple custom operations.
165167

166168
In such a case, you will probably create the same amount of custom controllers while you may not need to perform custom logic inside.
167169

168-
To avoid that, API Platform provides the `ApiPlatform\Action\PlaceholderAction` which behaves the same when using the [built-in operations](operations.md#operations).
170+
To avoid that, API Platform provides the `ApiPlatform\Action\PlaceholderAction` which behaves the same when using the [built-in operations](../core/operations.md#operations).
169171

170172
You just need to set the `controller` attribute with this class. Here, the previous example updated:
171173

@@ -370,7 +372,7 @@ resources:
370372

371373
</code-selector>
372374

373-
This way, it will skip the `ReadListener`. You can do the same for some other built-in listeners. See [Built-in Event Listeners](events.md#built-in-event-listeners)
375+
This way, it will skip the `ReadListener`. You can do the same for some other built-in listeners. See [Built-in Event Listeners](../core/events.md#built-in-event-listeners)
374376
for more information.
375377

376378
In your custom controller, the `__invoke()` method parameter should be called the same as the entity identifier.

symfony/migrate-from-fosrestbundle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Same as above.
3333

3434
**In API Platform**
3535

36-
Even though this is not recommended, API Platform allows you to [create custom controllers](../core/controllers.md) and declare them in your entity's `ApiResource` attribute.
36+
Even though this is not recommended, API Platform allows you to [create custom controllers](controllers.md) and declare them in your entity's `ApiResource` attribute.
3737

3838
You can use them as you migrate from FOSRestBundle, but you should consider [switching to Symfony Messenger](../core/messenger.md) as it will give you more benefits, such as compatibility with both REST and GraphQL and better performances of your API on big tasks.
3939

0 commit comments

Comments
 (0)