You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add documentation on system providers and processors
This commit introduces detailed documentation on the workflow of state providers and processors in the system. It includes a schema, examples of decorating providers and processors, and specific implementations for both Symfony and Laravel frameworks.
Copy file name to clipboardExpand all lines: core/extending.md
+116Lines changed: 116 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -36,3 +36,119 @@ For instance, if you want to send a mail after a resource has been persisted, bu
36
36
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).
37
37
38
38
<palign="center"class="symfonycasts"><ahref="https://symfonycasts.com/screencast/api-platform-security/service-decoration?cid=apip"><imgsrc="../symfony/images/symfonycasts-player.png"alt="Service Decoration screencast"><br>Watch the Service Decoration screencast</a></p>
39
+
40
+
## System providers and processors
41
+
42
+
The system is based on a workflow composed of **state providers** and **state processors**
43
+
44
+
The schema below describes them:
45
+
46
+
```mermaid
47
+
---
48
+
title: System providers and processors
49
+
---
50
+
flowchart TB
51
+
C1(ReadProvider) --> C2(AccessCheckerProvider)
52
+
C2 --> C3(DeserializeProvider)
53
+
C3 --> C4(ParameterProvider)
54
+
C4 --> C5(ValidateProcessor)
55
+
C5 --> C6(WriteProcessor)
56
+
C6 --> C7(SerializeProcessor)
57
+
```
58
+
59
+
### Symfony Access Checker Provider
60
+
61
+
When using Symfony, the access checker provider is used at three different stages:
62
+
-`api_platform.state_provider.access_checker.post_validate` decorates the ValidateProvider
63
+
-`api_platform.state_provider.access_checker.post_deserialize` decorates the DeserializeProvider
64
+
-`api_platform.state_provider.access_checker` decorates the ReadProvider
65
+
66
+
67
+
### Decoration example
68
+
69
+
Here is an example of the decoration of the RespondProcessor:
70
+
71
+
Starts by creating your `CustomRespondProcessor`:
72
+
```php
73
+
<?php
74
+
namespace App\State;
75
+
76
+
use ApiPlatform\State\ProcessorInterface;
77
+
78
+
final class CustomRespondProcessor implements ProcessorInterface
79
+
{
80
+
public function __construct(private readonly ProcessorInterface $processor){}
81
+
82
+
public function __invoke($data, string $resourceClass, string $operationName, array $context)
83
+
{
84
+
// You can add pre-write code here.
85
+
86
+
// Call the decorated write stage (this syntax calls the __invoke method).
0 commit comments