Skip to content

Commit 99fac74

Browse files
committed
add dedicated method for disabling instead of passing boolean flags
1 parent 8075c68 commit 99fac74

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

src/Symfony/Component/Messenger/Command/FailedMessagesRemoveCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ private function removeMessages(string $failureTransportName, array $ids, Receiv
7474
}
7575

7676
foreach ($ids as $id) {
77-
$this->phpSerializer?->enableClassNotFoundCreation();
77+
$this->phpSerializer?->acceptPhpIncompleteClass();
7878
try {
7979
$envelope = $receiver->find($id);
8080
} finally {
81-
$this->phpSerializer?->enableClassNotFoundCreation(false);
81+
$this->phpSerializer?->rejectPhpIncompleteClass();
8282
}
8383

8484
if (null === $envelope) {

src/Symfony/Component/Messenger/Command/FailedMessagesRetryCommand.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ private function runInteractive(string $failureTransportName, SymfonyStyle $io,
135135
// handling the message
136136
while (true) {
137137
$envelopes = [];
138-
$this->phpSerializer?->enableClassNotFoundCreation();
138+
$this->phpSerializer?->acceptPhpIncompleteClass();
139139
try {
140140
foreach ($receiver->all(1) as $envelope) {
141141
++$count;
142142
$envelopes[] = $envelope;
143143
}
144144
} finally {
145-
$this->phpSerializer?->enableClassNotFoundCreation(false);
145+
$this->phpSerializer?->rejectPhpIncompleteClass();
146146
}
147147

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

214214
foreach ($ids as $id) {
215-
$this->phpSerializer?->enableClassNotFoundCreation();
215+
$this->phpSerializer?->acceptPhpIncompleteClass();
216216
try {
217217
$envelope = $receiver->find($id);
218218
} finally {
219-
$this->phpSerializer?->enableClassNotFoundCreation(false);
219+
$this->phpSerializer?->rejectPhpIncompleteClass();
220220
}
221221
if (null === $envelope) {
222222
throw new RuntimeException(sprintf('The message "%s" was not found.', $id));

src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private function listMessages(?string $failedTransportName, SymfonyStyle $io, in
9696
$io->comment(sprintf('Displaying only \'%s\' messages', $classFilter));
9797
}
9898

99-
$this->phpSerializer?->enableClassNotFoundCreation();
99+
$this->phpSerializer?->acceptPhpIncompleteClass();
100100
try {
101101
foreach ($envelopes as $envelope) {
102102
$currentClassName = \get_class($envelope->getMessage());
@@ -118,7 +118,7 @@ private function listMessages(?string $failedTransportName, SymfonyStyle $io, in
118118
];
119119
}
120120
} finally {
121-
$this->phpSerializer?->enableClassNotFoundCreation(false);
121+
$this->phpSerializer?->rejectPhpIncompleteClass();
122122
}
123123

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

149149
$countPerClass = [];
150150

151-
$this->phpSerializer?->enableClassNotFoundCreation();
151+
$this->phpSerializer?->acceptPhpIncompleteClass();
152152
try {
153153
foreach ($envelopes as $envelope) {
154154
$c = \get_class($envelope->getMessage());
@@ -160,7 +160,7 @@ private function listMessagesPerClass(?string $failedTransportName, SymfonyStyle
160160
++$countPerClass[$c][1];
161161
}
162162
} finally {
163-
$this->phpSerializer?->enableClassNotFoundCreation(false);
163+
$this->phpSerializer?->rejectPhpIncompleteClass();
164164
}
165165

166166
if (0 === \count($countPerClass)) {
@@ -176,11 +176,11 @@ private function showMessage(?string $failedTransportName, string $id, SymfonySt
176176
{
177177
/** @var ListableReceiverInterface $receiver */
178178
$receiver = $this->getReceiver($failedTransportName);
179-
$this->phpSerializer?->enableClassNotFoundCreation();
179+
$this->phpSerializer?->acceptPhpIncompleteClass();
180180
try {
181181
$envelope = $receiver->find($id);
182182
} finally {
183-
$this->phpSerializer?->enableClassNotFoundCreation(false);
183+
$this->phpSerializer?->rejectPhpIncompleteClass();
184184
}
185185
if (null === $envelope) {
186186
throw new RuntimeException(sprintf('The message "%s" was not found.', $id));

src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerWithClassNotFoundSupportTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testDecodingFailsButCreateClassNotFound()
6565
protected function createPhpSerializer(): PhpSerializer
6666
{
6767
$serializer = new PhpSerializer();
68-
$serializer->enableClassNotFoundCreation();
68+
$serializer->acceptPhpIncompleteClass();
6969

7070
return $serializer;
7171
}

src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@
2121
*/
2222
class PhpSerializer implements SerializerInterface
2323
{
24-
private bool $createClassNotFound = false;
24+
private bool $acceptPhpIncompleteClass = false;
2525

26-
public function enableClassNotFoundCreation(bool $enable = true): void
26+
/**
27+
* @internal
28+
*/
29+
public function acceptPhpIncompleteClass(): void
30+
{
31+
$this->acceptPhpIncompleteClass = true;
32+
}
33+
34+
/**
35+
* @internal
36+
*/
37+
public function rejectPhpIncompleteClass(): void
2738
{
28-
$this->createClassNotFound = $enable;
39+
$this->acceptPhpIncompleteClass = false;
2940
}
3041

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

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

69-
if ($this->createClassNotFound) {
80+
if ($this->acceptPhpIncompleteClass) {
7081
$prevUnserializeHandler = ini_set('unserialize_callback_func', null);
7182
} else {
7283
$prevUnserializeHandler = ini_set('unserialize_callback_func', self::class.'::handleUnserializeCallback');

0 commit comments

Comments
 (0)