Permalink
Browse files

bug #21557 [VarDumper] Improve dump of AMQP* Object (lyrixx)

This PR was merged into the 2.8 branch.

Discussion
----------

[VarDumper] Improve dump of AMQP* Object

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

---

The release of https://github.com/pdezwart/php-amqp/ 1.7.0alpha1
changed internally the handling of AMQP* object. So now when dumping
using var_dump(), many information are available. So many information
are displayed twice. This commit fixes this issue and keeps displaying basic
information for older versions of the lib.

Reference:

* https://pecl.php.net/package-info.php?package=amqp&version=1.7.0alpha1
* pdezwart/php-amqp@314afbc (and next commits)

---

![screenshot4](https://cloud.githubusercontent.com/assets/408368/22700884/53ad5f68-ed5c-11e6-986b-bfdf91640060.png)

![screenshot5](https://cloud.githubusercontent.com/assets/408368/22700890/580353c4-ed5c-11e6-8fc8-c101115b7001.png)

Commits
-------

c553352 [VarDumper] Improve dump of AMQP* Object
  • Loading branch information...
2 parents c346f2a + c553352 commit f6744d64d989548cd54e61419e615a19b7d6bdc6 @nicolas-grekas nicolas-grekas committed Feb 11, 2017
Showing with 74 additions and 28 deletions.
  1. +74 −28 src/Symfony/Component/VarDumper/Caster/AmqpCaster.php
@@ -48,6 +48,15 @@ public static function castConnection(\AMQPConnection $c, array $a, Stub $stub,
{
$prefix = Caster::PREFIX_VIRTUAL;
+ $a += array(
+ $prefix.'is_connected' => $c->isConnected(),
+ );
+
+ // Recent version of the extension already expose private properties
+ if (isset($a["\x00AMQPConnection\x00login"])) {
+ return $a;
+ }
+
// BC layer in the amqp lib
if (method_exists($c, 'getReadTimeout')) {
$timeout = $c->getReadTimeout();
@@ -56,13 +65,13 @@ public static function castConnection(\AMQPConnection $c, array $a, Stub $stub,
}
$a += array(
- $prefix.'isConnected' => $c->isConnected(),
+ $prefix.'is_connected' => $c->isConnected(),
$prefix.'login' => $c->getLogin(),
$prefix.'password' => $c->getPassword(),
$prefix.'host' => $c->getHost(),
- $prefix.'port' => $c->getPort(),
$prefix.'vhost' => $c->getVhost(),
- $prefix.'readTimeout' => $timeout,
+ $prefix.'port' => $c->getPort(),
+ $prefix.'read_timeout' => $timeout,
);
return $a;
@@ -73,11 +82,19 @@ public static function castChannel(\AMQPChannel $c, array $a, Stub $stub, $isNes
$prefix = Caster::PREFIX_VIRTUAL;
$a += array(
- $prefix.'isConnected' => $c->isConnected(),
- $prefix.'channelId' => $c->getChannelId(),
- $prefix.'prefetchSize' => $c->getPrefetchSize(),
- $prefix.'prefetchCount' => $c->getPrefetchCount(),
+ $prefix.'is_connected' => $c->isConnected(),
+ $prefix.'channel_id' => $c->getChannelId(),
+ );
+
+ // Recent version of the extension already expose private properties
+ if (isset($a["\x00AMQPChannel\x00connection"])) {
+ return $a;
+ }
+
+ $a += array(
$prefix.'connection' => $c->getConnection(),
+ $prefix.'prefetch_size' => $c->getPrefetchSize(),
+ $prefix.'prefetch_count' => $c->getPrefetchCount(),
);
return $a;
@@ -88,11 +105,19 @@ public static function castQueue(\AMQPQueue $c, array $a, Stub $stub, $isNested)
$prefix = Caster::PREFIX_VIRTUAL;
$a += array(
- $prefix.'name' => $c->getName(),
$prefix.'flags' => self::extractFlags($c->getFlags()),
- $prefix.'arguments' => $c->getArguments(),
+ );
+
+ // Recent version of the extension already expose private properties
+ if (isset($a["\x00AMQPQueue\x00name"])) {
+ return $a;
+ }
+
+ $a += array(
$prefix.'connection' => $c->getConnection(),
$prefix.'channel' => $c->getChannel(),
+ $prefix.'name' => $c->getName(),
+ $prefix.'arguments' => $c->getArguments(),
);
return $a;
@@ -103,12 +128,24 @@ public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, $isN
$prefix = Caster::PREFIX_VIRTUAL;
$a += array(
- $prefix.'name' => $c->getName(),
$prefix.'flags' => self::extractFlags($c->getFlags()),
- $prefix.'type' => isset(self::$exchangeTypes[$c->getType()]) ? new ConstStub(self::$exchangeTypes[$c->getType()], $c->getType()) : $c->getType(),
- $prefix.'arguments' => $c->getArguments(),
- $prefix.'channel' => $c->getChannel(),
+ );
+
+ $type = isset(self::$exchangeTypes[$c->getType()]) ? new ConstStub(self::$exchangeTypes[$c->getType()], $c->getType()) : $c->getType();
+
+ // Recent version of the extension already expose private properties
+ if (isset($a["\x00AMQPExchange\x00name"])) {
+ $a["\x00AMQPExchange\x00type"] = $type;
+
+ return $a;
+ }
+
+ $a += array(
$prefix.'connection' => $c->getConnection(),
+ $prefix.'channel' => $c->getChannel(),
+ $prefix.'name' => $c->getName(),
+ $prefix.'type' => $type,
+ $prefix.'arguments' => $c->getArguments(),
);
return $a;
@@ -118,28 +155,37 @@ public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, $isN
{
$prefix = Caster::PREFIX_VIRTUAL;
+ $deliveryMode = new ConstStub($c->getDeliveryMode().(2 === $c->getDeliveryMode() ? ' (persistent)' : ' (non-persistent)'), $c->getDeliveryMode());
+
+ // Recent version of the extension already expose private properties
+ if (isset($a["\x00AMQPEnvelope\x00body"])) {
+ $a["\0AMQPEnvelope\0delivery_mode"] = $deliveryMode;
+
+ return $a;
+ }
+
if (!($filter & Caster::EXCLUDE_VERBOSE)) {
$a += array($prefix.'body' => $c->getBody());
}
$a += array(
- $prefix.'routingKey' => $c->getRoutingKey(),
- $prefix.'deliveryTag' => $c->getDeliveryTag(),
- $prefix.'deliveryMode' => new ConstStub($c->getDeliveryMode().(2 === $c->getDeliveryMode() ? ' (persistent)' : ' (non-persistent)'), $c->getDeliveryMode()),
- $prefix.'exchangeName' => $c->getExchangeName(),
- $prefix.'isRedelivery' => $c->isRedelivery(),
- $prefix.'contentType' => $c->getContentType(),
- $prefix.'contentEncoding' => $c->getContentEncoding(),
- $prefix.'type' => $c->getType(),
- $prefix.'timestamp' => $c->getTimeStamp(),
+ $prefix.'delivery_tag' => $c->getDeliveryTag(),
+ $prefix.'is_redelivery' => $c->isRedelivery(),
+ $prefix.'exchange_name' => $c->getExchangeName(),
+ $prefix.'routing_key' => $c->getRoutingKey(),
+ $prefix.'content_type' => $c->getContentType(),
+ $prefix.'content_encoding' => $c->getContentEncoding(),
+ $prefix.'headers' => $c->getHeaders(),
+ $prefix.'delivery_mode' => $deliveryMode,
$prefix.'priority' => $c->getPriority(),
+ $prefix.'correlation_id' => $c->getCorrelationId(),
+ $prefix.'reply_to' => $c->getReplyTo(),
$prefix.'expiration' => $c->getExpiration(),
- $prefix.'userId' => $c->getUserId(),
- $prefix.'appId' => $c->getAppId(),
- $prefix.'messageId' => $c->getMessageId(),
- $prefix.'replyTo' => $c->getReplyTo(),
- $prefix.'correlationId' => $c->getCorrelationId(),
- $prefix.'headers' => $c->getHeaders(),
+ $prefix.'message_id' => $c->getMessageId(),
+ $prefix.'timestamp' => $c->getTimeStamp(),
+ $prefix.'type' => $c->getType(),
+ $prefix.'user_id' => $c->getUserId(),
+ $prefix.'app_id' => $c->getAppId(),
);
return $a;

0 comments on commit f6744d6

Please sign in to comment.