Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ private function removeMessages(string $failureTransportName, array $ids, Receiv
}

foreach ($ids as $id) {
$this->phpSerializer?->enableClassNotFoundCreation();
$this->phpSerializer?->acceptPhpIncompleteClass();
try {
$envelope = $receiver->find($id);
} finally {
$this->phpSerializer?->enableClassNotFoundCreation(false);
$this->phpSerializer?->rejectPhpIncompleteClass();
}

if (null === $envelope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ private function runInteractive(string $failureTransportName, SymfonyStyle $io,
// handling the message
while (true) {
$envelopes = [];
$this->phpSerializer?->enableClassNotFoundCreation();
$this->phpSerializer?->acceptPhpIncompleteClass();
try {
foreach ($receiver->all(1) as $envelope) {
++$count;
$envelopes[] = $envelope;
}
} finally {
$this->phpSerializer?->enableClassNotFoundCreation(false);
$this->phpSerializer?->rejectPhpIncompleteClass();
}

// break the loop if all messages are consumed
Expand Down Expand Up @@ -212,11 +212,11 @@ private function retrySpecificIds(string $failureTransportName, array $ids, Symf
}

foreach ($ids as $id) {
$this->phpSerializer?->enableClassNotFoundCreation();
$this->phpSerializer?->acceptPhpIncompleteClass();
try {
$envelope = $receiver->find($id);
} finally {
$this->phpSerializer?->enableClassNotFoundCreation(false);
$this->phpSerializer?->rejectPhpIncompleteClass();
}
if (null === $envelope) {
throw new RuntimeException(sprintf('The message "%s" was not found.', $id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function listMessages(?string $failedTransportName, SymfonyStyle $io, in
$io->comment(sprintf('Displaying only \'%s\' messages', $classFilter));
}

$this->phpSerializer?->enableClassNotFoundCreation();
$this->phpSerializer?->acceptPhpIncompleteClass();
try {
foreach ($envelopes as $envelope) {
$currentClassName = \get_class($envelope->getMessage());
Expand All @@ -118,7 +118,7 @@ private function listMessages(?string $failedTransportName, SymfonyStyle $io, in
];
}
} finally {
$this->phpSerializer?->enableClassNotFoundCreation(false);
$this->phpSerializer?->rejectPhpIncompleteClass();
}

$rowsCount = \count($rows);
Expand Down Expand Up @@ -148,7 +148,7 @@ private function listMessagesPerClass(?string $failedTransportName, SymfonyStyle

$countPerClass = [];

$this->phpSerializer?->enableClassNotFoundCreation();
$this->phpSerializer?->acceptPhpIncompleteClass();
try {
foreach ($envelopes as $envelope) {
$c = \get_class($envelope->getMessage());
Expand All @@ -160,7 +160,7 @@ private function listMessagesPerClass(?string $failedTransportName, SymfonyStyle
++$countPerClass[$c][1];
}
} finally {
$this->phpSerializer?->enableClassNotFoundCreation(false);
$this->phpSerializer?->rejectPhpIncompleteClass();
}

if (0 === \count($countPerClass)) {
Expand All @@ -176,11 +176,11 @@ private function showMessage(?string $failedTransportName, string $id, SymfonySt
{
/** @var ListableReceiverInterface $receiver */
$receiver = $this->getReceiver($failedTransportName);
$this->phpSerializer?->enableClassNotFoundCreation();
$this->phpSerializer?->acceptPhpIncompleteClass();
try {
$envelope = $receiver->find($id);
} finally {
$this->phpSerializer?->enableClassNotFoundCreation(false);
$this->phpSerializer?->rejectPhpIncompleteClass();
}
if (null === $envelope) {
throw new RuntimeException(sprintf('The message "%s" was not found.', $id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testDecodingFailsButCreateClassNotFound()
protected function createPhpSerializer(): PhpSerializer
{
$serializer = new PhpSerializer();
$serializer->enableClassNotFoundCreation();
$serializer->acceptPhpIncompleteClass();

return $serializer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@
*/
class PhpSerializer implements SerializerInterface
{
private bool $createClassNotFound = false;
private bool $acceptPhpIncompleteClass = false;

public function enableClassNotFoundCreation(bool $enable = true): void
/**
* @internal
*/
public function acceptPhpIncompleteClass(): void
{
$this->acceptPhpIncompleteClass = true;
}

/**
* @internal
*/
public function rejectPhpIncompleteClass(): void
{
$this->createClassNotFound = $enable;
$this->acceptPhpIncompleteClass = false;
}

public function decode(array $encodedEnvelope): Envelope
Expand Down Expand Up @@ -66,7 +77,7 @@ private function safelyUnserialize(string $contents): Envelope

$signalingException = new MessageDecodingFailedException(sprintf('Could not decode message using PHP serialization: %s.', $contents));

if ($this->createClassNotFound) {
if ($this->acceptPhpIncompleteClass) {
$prevUnserializeHandler = ini_set('unserialize_callback_func', null);
} else {
$prevUnserializeHandler = ini_set('unserialize_callback_func', self::class.'::handleUnserializeCallback');
Expand Down