-
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
929625e
commit f062fe7
Showing
17 changed files
with
704 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\State\Processor; | ||
|
||
use ApiPlatform\Api\IriConverterInterface; | ||
use ApiPlatform\Api\UrlGeneratorInterface; | ||
use ApiPlatform\Doctrine\Common\State\RemoveProcessor as DoctrineRemoveProcessor; | ||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; | ||
use ApiPlatform\State\ProcessorInterface; | ||
use App\Entity\Book; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
final readonly class BookRemoveProcessor implements ProcessorInterface | ||
{ | ||
public function __construct( | ||
#[Autowire(service: DoctrineRemoveProcessor::class)] | ||
private ProcessorInterface $removeProcessor, | ||
#[Autowire(service: MercureProcessor::class)] | ||
private ProcessorInterface $mercureProcessor, | ||
private ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, | ||
private IriConverterInterface $iriConverter | ||
) { | ||
} | ||
|
||
/** | ||
* @param Book $data | ||
*/ | ||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): Book | ||
{ | ||
$object = clone $data; | ||
|
||
// remove entity | ||
$this->removeProcessor->process($data, $operation, $uriVariables, $context); | ||
|
||
// publish on Mercure | ||
// todo find a way to do it in API Platform | ||
foreach (['/admin/books/{id}{._format}', '/books/{id}{._format}'] as $uriTemplate) { | ||
$iri = $this->iriConverter->getIriFromResource( | ||
$object, | ||
UrlGeneratorInterface::ABS_URL, | ||
$this->resourceMetadataCollectionFactory->create(Book::class)->getOperation($uriTemplate) | ||
); | ||
$this->mercureProcessor->process( | ||
$object, | ||
$operation, | ||
$uriVariables, | ||
$context + [ | ||
'item_uri_template' => $uriTemplate, | ||
'data' => json_encode(['@id' => $iri]), | ||
] | ||
); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
Oops, something went wrong.