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
Copy file name to clipboardExpand all lines: core/state-processors.md
+11-10Lines changed: 11 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -81,9 +81,9 @@ services:
81
81
#tags: [ 'api_platform.state_processor' ]
82
82
```
83
83
84
-
## Decorating the Built-In State Processors
84
+
## Hooking into the Built-In State Processors
85
85
86
-
If you want to execute custom business logic before or after persistence, this can be achieved by [decorating](https://symfony.com/doc/current/service_container/service_decoration.html) the built-in state processors.
86
+
If you want to execute custom business logic before or after persistence, this can be achieved by [decorating](https://symfony.com/doc/current/service_container/service_decoration.html) the built-in state processors or using [composition](https://en.wikipedia.org/wiki/Object_composition).
87
87
88
88
The next example uses [Symfony Mailer](https://symfony.com/doc/current/mailer.html). Read its documentation if you want to use it.
89
89
@@ -94,25 +94,25 @@ Here is an implementation example which sends new users a welcome email after a
94
94
95
95
namespace App\State;
96
96
97
+
use ApiPlatform\Metadata\DeleteOperationInterface;
97
98
use ApiPlatform\Metadata\Operation;
98
99
use ApiPlatform\State\ProcessorInterface;
99
100
use App\Entity\User;
100
101
use Symfony\Component\Mailer\MailerInterface;
101
102
102
103
final class UserProcessor implements ProcessorInterface
103
104
{
104
-
private $decorated;
105
-
private $mailer;
106
-
107
-
public function __construct(ProcessorInterface $decorated, MailerInterface $mailer)
105
+
public function __construct(private ProcessorInterface $persistProcessor, private ProcessorInterface $removeProcessor, MailerInterface $mailer)
108
106
{
109
-
$this->decorated = $decorated;
110
-
$this->mailer = $mailer;
111
107
}
112
108
113
109
public function process($data, Operation $operation, array $uriVariables = [], array $context = [])
0 commit comments