feature #28397 [Messenger] Change exceptions to use component's one (fabpot)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Messenger] Change exceptions to use component's one

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Commits
-------

4e0e5e5fdb [Messenger] changed exceptions to use component's one
This commit is contained in:
Fabien Potencier 2018-09-08 13:58:28 +02:00
commit a480dc6a85
4 changed files with 12 additions and 5 deletions

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Messenger\Handler;
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
/**
* Represents a collection of message handlers.
*
@ -29,7 +31,7 @@ class ChainHandler
public function __construct(array $handlers)
{
if (empty($handlers)) {
throw new \InvalidArgumentException('A collection of message handlers requires at least one handler.');
throw new InvalidArgumentException('A collection of message handlers requires at least one handler.');
}
$this->handlers = $handlers;

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Messenger\Transport\AmqpExt;
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
/**
* An AMQP connection.
*
@ -51,7 +53,7 @@ class Connection
public static function fromDsn(string $dsn, array $options = array(), bool $debug = false, AmqpFactory $amqpFactory = null): self
{
if (false === $parsedUrl = parse_url($dsn)) {
throw new \InvalidArgumentException(sprintf('The given AMQP DSN "%s" is invalid.', $dsn));
throw new InvalidArgumentException(sprintf('The given AMQP DSN "%s" is invalid.', $dsn));
}
$pathParts = isset($parsedUrl['path']) ? explode('/', trim($parsedUrl['path'], '/')) : array();

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Messenger\Transport\Serialization;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\SerializerInterface;
/**
@ -36,11 +37,11 @@ class Serializer implements DecoderInterface, EncoderInterface
public function decode(array $encodedEnvelope): Envelope
{
if (empty($encodedEnvelope['body']) || empty($encodedEnvelope['headers'])) {
throw new \InvalidArgumentException('Encoded envelope should have at least a `body` and some `headers`.');
throw new InvalidArgumentException('Encoded envelope should have at least a "body" and some "headers".');
}
if (empty($encodedEnvelope['headers']['type'])) {
throw new \InvalidArgumentException('Encoded envelope does not have a `type` header.');
throw new InvalidArgumentException('Encoded envelope does not have a "type" header.');
}
$envelopeItems = $this->decodeEnvelopeItems($encodedEnvelope);

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Messenger\Transport;
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
/**
* @author Samuel Roze <samuel.roze@gmail.com>
*/
@ -34,7 +36,7 @@ class TransportFactory implements TransportFactoryInterface
}
}
throw new \InvalidArgumentException(sprintf('No transport supports the given DSN "%s".', $dsn));
throw new InvalidArgumentException(sprintf('No transport supports the given DSN "%s".', $dsn));
}
public function supports(string $dsn, array $options): bool