Skip to content

Commit c128c97

Browse files
committed
Symfony Messenger 4.2 Compatability
Signed-off-by: RJ Garcia <rj@bighead.net>
1 parent aae9e31 commit c128c97

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/DataPersister/MessageBusDataPersister.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Krak\ApiPlatformExtra\DataPersister;
44

55
use ApiPlatform\Core\DataPersister\DataPersisterInterface;
6+
use Symfony\Component\Messenger\Envelope;
67
use Symfony\Component\Messenger\MessageBusInterface;
8+
use Symfony\Component\Messenger\Stamp\HandledStamp;
79

810
final class MessageBusDataPersister implements DataPersisterInterface
911
{
@@ -32,7 +34,16 @@ public function supports($data): bool {
3234
* @return object|void Void will not be supported in API Platform 3, an object should always be returned
3335
*/
3436
public function persist($data) {
35-
return $this->messageBus->dispatch($data);
37+
$envelope = $this->messageBus->dispatch($data);
38+
if ($envelope instanceof Envelope === false) {
39+
return $envelope;
40+
}
41+
42+
if (null === $stamp = $envelope->last(HandledStamp::class)) {
43+
return $data;
44+
}
45+
46+
return $stamp->getResult();
3647
}
3748

3849
/**

0 commit comments

Comments
 (0)