for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Core\Bridge\Symfony\Messenger;
use ApiPlatform\Core\DataPersister\DataPersisterInterface;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Util\ClassInfoTrait;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
/**
* Dispatches the given resource using the message bus of Symfony Messenger.
* @experimental
* @author Kévin Dunglas <[email protected]>
final class DataPersister implements DataPersisterInterface
{
use ClassInfoTrait;
private $resourceMetadataFactory;
private $messageBus;
public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, MessageBusInterface $messageBus)
$this->resourceMetadataFactory = $resourceMetadataFactory;
$this->messageBus = $messageBus;
}
* {@inheritdoc}
public function supports($data): bool
return true === $this->resourceMetadataFactory->create($this->getObjectClass($data))->getAttribute('messenger');
public function persist($data)
$this->messageBus->dispatch($data);
return $data;
public function remove($data)
$this->messageBus->dispatch(new Envelope($data, new RemoveStamp()));