Skip to content

Commit 55b9fff

Browse files
committed
Using ResetInterface
1 parent 97810ce commit 55b9fff

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

src/Symfony/Component/Messenger/Exception/MessageRecorderHandlerException.php renamed to src/Symfony/Component/Messenger/Exception/MessageHandlingException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
namespace Symfony\Component\Messenger\Exception;
1313

1414
/**
15-
* When handling recorded messaged one or more handlers caused an exception.
16-
* This exception contains all those handler exceptions.
15+
* When handling messages, sore handlers caused an exception. This exception
16+
* contains all those handler exceptions.
1717
*
1818
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
1919
*/
20-
class MessageRecorderHandlerException extends \RuntimeException implements ExceptionInterface
20+
class MessageHandlingException extends \RuntimeException implements ExceptionInterface
2121
{
2222
private $exceptions = array();
2323

2424
public function __construct(array $exceptions)
2525
{
2626
$message = sprintf(
27-
"One or more handlers for recorded messages threw an exception. Their messages were: \n\n%s",
27+
"Some handlers for recorded messages threw an exception. Their messages were: \n\n%s",
2828
implode(", \n", array_map(function (\Throwable $e) {
2929
return $e->getMessage();
3030
}, $exceptions))

src/Symfony/Component/Messenger/MessageRecorderInterface.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
namespace Symfony\Component\Messenger;
1313

14+
use Symfony\Contracts\Service\ResetInterface;
15+
1416
/**
1517
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
1618
* @author Matthias Noback <matthiasnoback@gmail.com>
1719
*/
18-
interface MessageRecorderInterface
20+
interface MessageRecorderInterface extends ResetInterface
1921
{
2022
/**
2123
* Fetch recorded messages.
@@ -24,11 +26,6 @@ interface MessageRecorderInterface
2426
*/
2527
public function fetch(): array;
2628

27-
/**
28-
* Erase messages that were recorded since the last call to eraseMessages().
29-
*/
30-
public function reset();
31-
3229
/**
3330
* Record a message.
3431
*

src/Symfony/Component/Messenger/Middleware/HandlesRecordedMessagesMiddleware.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Messenger\Middleware;
1313

14-
use Symfony\Component\Messenger\Exception\MessageRecorderHandlerException;
14+
use Symfony\Component\Messenger\Exception\MessageHandlingException;
1515
use Symfony\Component\Messenger\MessageBusInterface;
1616
use Symfony\Component\Messenger\MessageRecorderInterface;
1717

@@ -35,19 +35,19 @@ public function __construct(MessageBusInterface $messageBus, MessageRecorderInte
3535
public function handle($message, callable $next)
3636
{
3737
// Make sure the recorder is empty before we begin
38-
$this->messageRecorder->erase();
38+
$this->messageRecorder->reset();
3939

4040
try {
4141
$next($message);
4242
} catch (\Throwable $exception) {
43-
$this->messageRecorder->erase();
43+
$this->messageRecorder->reset();
4444

4545
throw $exception;
4646
}
4747

4848
$exceptions = array();
4949
while (!empty($recordedMessages = $this->messageRecorder->fetch())) {
50-
$this->messageRecorder->erase();
50+
$this->messageRecorder->reset();
5151
// Assert: The message recorder is empty, all messages are in $recordedMessages
5252

5353
foreach ($recordedMessages as $recordedMessage) {
@@ -60,7 +60,10 @@ public function handle($message, callable $next)
6060
}
6161

6262
if (!empty($exceptions)) {
63-
throw MessageRecorderHandlerException::create($exceptions);
63+
if (count($exceptions) === 1) {
64+
throw $exceptions[0];
65+
}
66+
throw new MessageHandlingException($exceptions);
6467
}
6568
}
6669
}

src/Symfony/Component/Messenger/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"require-dev": {
2222
"psr/log": "~1.0",
2323
"symfony/console": "~3.4|~4.0",
24+
"symfony/contracts": "^1.0",
2425
"symfony/dependency-injection": "~3.4.6|~4.0",
2526
"symfony/http-kernel": "~3.4|~4.0",
2627
"symfony/process": "~3.4|~4.0",

0 commit comments

Comments
 (0)