-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
ReviewRemoveProcessor.php
46 lines (39 loc) · 1.43 KB
/
ReviewRemoveProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace App\State\Processor;
use ApiPlatform\Doctrine\Common\State\RemoveProcessor;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\Review;
use App\Security\Http\Protection\ResourceHandlerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
/**
* @implements ProcessorInterface<Review, void>
*/
final readonly class ReviewRemoveProcessor implements ProcessorInterface
{
/**
* @param RemoveProcessor $removeProcessor
*/
public function __construct(
#[Autowire(service: RemoveProcessor::class)]
private ProcessorInterface $removeProcessor,
private ResourceHandlerInterface $resourceHandler,
) {
}
/**
* @param Review $data
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void
{
$object = clone $data;
// remove entity
$this->removeProcessor->process($data, $operation, $uriVariables, $context);
// project specification: only delete resource on OIDC server for known users (john.doe and chuck.norris)
if (\in_array($object->user->email, ['[email protected]', '[email protected]'], true)) {
$this->resourceHandler->delete($object, $object->user, [
'operation_name' => '/books/{bookId}/reviews/{id}{._format}',
]);
}
}
}