PHP code example of velpl / symfony-messenger-outbox-bundle
1. Go to this page and download the library: Download velpl/symfony-messenger-outbox-bundle library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
velpl / symfony-messenger-outbox-bundle example snippets
declare(strict_types=1);
namespace App\Message\Command;
use Velpl\SymfonyMessengerOutboxBundle\Messenger\Outbox\Attribute\AsOutboxTransport;
// .........
#[AsOutboxTransport('async_todo_creation')]
final readonly class CreateTodoCommand
{
public function __construct(private Todo $todo) {}
// rest of the class logic, usually some getters...
}
declare(strict_types=1);
namespace App\Command;
use App\Message\Command\CreateTodoCommand;
use Doctrine\ORM\EntityManagerInterface;
// ..........
final readonly class TodoApplication service {
public function __construct(
private EntityManagerInterface $entityManager,
private MessageBusInterface $messageBus
) {}
public function create(): void {
$todo = new Todo()
->setTitle('A todo list item')
;
$this->entityManager->wrapInTransaction(
function () use ($todo): void {
$this->entityManager->persist($todo);
$this->entityManager->flush();
$this->messageBus->dispatch(new CreateTodoCommand($todo))
}
);
}
}