Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e35853

Browse files
committed
[VarDumper] Improve dump of AMQP* Object
The release of https://github.com/pdezwart/php-amqp/ 1.7.0alpha1 changed internally the handlings of AMQP* object. So now when dumping using var_dump(), many information are availables. So many information are displayed twice. This commit fixes this issue and keeps displaying basic information for older version of the lib. Reference: * https://pecl.php.net/package-info.php?package=amqp&version=1.7.0alpha1 * php-amqp/php-amqp@314afbc (and next commits)
1 parent c346f2a commit 1e35853

File tree

1 file changed

+74
-28
lines changed

1 file changed

+74
-28
lines changed

src/Symfony/Component/VarDumper/Caster/AmqpCaster.php

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public static function castConnection(\AMQPConnection $c, array $a, Stub $stub,
4848
{
4949
$prefix = Caster::PREFIX_VIRTUAL;
5050

51+
$a += [
52+
$prefix.'is_connected' => $c->isConnected(),
53+
];
54+
55+
// Recent version of the extension already expose private properties
56+
if (isset($a["\x00AMQPConnection\x00login"])) {
57+
return $a;
58+
}
59+
5160
// BC layer in the amqp lib
5261
if (method_exists($c, 'getReadTimeout')) {
5362
$timeout = $c->getReadTimeout();
@@ -56,13 +65,13 @@ public static function castConnection(\AMQPConnection $c, array $a, Stub $stub,
5665
}
5766

5867
$a += array(
59-
$prefix.'isConnected' => $c->isConnected(),
68+
$prefix.'is_connected' => $c->isConnected(),
6069
$prefix.'login' => $c->getLogin(),
6170
$prefix.'password' => $c->getPassword(),
6271
$prefix.'host' => $c->getHost(),
63-
$prefix.'port' => $c->getPort(),
6472
$prefix.'vhost' => $c->getVhost(),
65-
$prefix.'readTimeout' => $timeout,
73+
$prefix.'port' => $c->getPort(),
74+
$prefix.'read_timeout' => $timeout,
6675
);
6776

6877
return $a;
@@ -73,11 +82,19 @@ public static function castChannel(\AMQPChannel $c, array $a, Stub $stub, $isNes
7382
$prefix = Caster::PREFIX_VIRTUAL;
7483

7584
$a += array(
76-
$prefix.'isConnected' => $c->isConnected(),
77-
$prefix.'channelId' => $c->getChannelId(),
78-
$prefix.'prefetchSize' => $c->getPrefetchSize(),
79-
$prefix.'prefetchCount' => $c->getPrefetchCount(),
85+
$prefix.'is_connected' => $c->isConnected(),
86+
$prefix.'channel_id' => $c->getChannelId(),
87+
);
88+
89+
// Recent version of the extension already expose private properties
90+
if (isset($a["\x00AMQPChannel\x00connection"])) {
91+
return $a;
92+
}
93+
94+
$a += array(
8095
$prefix.'connection' => $c->getConnection(),
96+
$prefix.'prefetch_size' => $c->getPrefetchSize(),
97+
$prefix.'prefetch_count' => $c->getPrefetchCount(),
8198
);
8299

83100
return $a;
@@ -88,11 +105,19 @@ public static function castQueue(\AMQPQueue $c, array $a, Stub $stub, $isNested)
88105
$prefix = Caster::PREFIX_VIRTUAL;
89106

90107
$a += array(
91-
$prefix.'name' => $c->getName(),
92108
$prefix.'flags' => self::extractFlags($c->getFlags()),
93-
$prefix.'arguments' => $c->getArguments(),
109+
);
110+
111+
// Recent version of the extension already expose private properties
112+
if (isset($a["\x00AMQPQueue\x00name"])) {
113+
return $a;
114+
}
115+
116+
$a += array(
94117
$prefix.'connection' => $c->getConnection(),
95118
$prefix.'channel' => $c->getChannel(),
119+
$prefix.'name' => $c->getName(),
120+
$prefix.'arguments' => $c->getArguments(),
96121
);
97122

98123
return $a;
@@ -103,12 +128,24 @@ public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, $isN
103128
$prefix = Caster::PREFIX_VIRTUAL;
104129

105130
$a += array(
106-
$prefix.'name' => $c->getName(),
107131
$prefix.'flags' => self::extractFlags($c->getFlags()),
108-
$prefix.'type' => isset(self::$exchangeTypes[$c->getType()]) ? new ConstStub(self::$exchangeTypes[$c->getType()], $c->getType()) : $c->getType(),
109-
$prefix.'arguments' => $c->getArguments(),
110-
$prefix.'channel' => $c->getChannel(),
132+
);
133+
134+
$type = isset(self::$exchangeTypes[$c->getType()]) ? new ConstStub(self::$exchangeTypes[$c->getType()], $c->getType()) : $c->getType();
135+
136+
// Recent version of the extension already expose private properties
137+
if (isset($a["\x00AMQPExchange\x00name"])) {
138+
$a["\x00AMQPExchange\x00type"] = $type;
139+
140+
return $a;
141+
}
142+
143+
$a += array(
111144
$prefix.'connection' => $c->getConnection(),
145+
$prefix.'channel' => $c->getChannel(),
146+
$prefix.'name' => $c->getName(),
147+
$prefix.'type' => $type,
148+
$prefix.'arguments' => $c->getArguments(),
112149
);
113150

114151
return $a;
@@ -118,28 +155,37 @@ public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, $isN
118155
{
119156
$prefix = Caster::PREFIX_VIRTUAL;
120157

158+
$deliveryMode = new ConstStub($c->getDeliveryMode().(2 === $c->getDeliveryMode() ? ' (persistent)' : ' (non-persistent)'), $c->getDeliveryMode());
159+
160+
// Recent version of the extension already expose private properties
161+
if (isset($a["\x00AMQPEnvelope\x00body"])) {
162+
$a["\0AMQPEnvelope\0delivery_mode"] = $deliveryMode;
163+
164+
return $a;
165+
}
166+
121167
if (!($filter & Caster::EXCLUDE_VERBOSE)) {
122168
$a += array($prefix.'body' => $c->getBody());
123169
}
124170

125171
$a += array(
126-
$prefix.'routingKey' => $c->getRoutingKey(),
127-
$prefix.'deliveryTag' => $c->getDeliveryTag(),
128-
$prefix.'deliveryMode' => new ConstStub($c->getDeliveryMode().(2 === $c->getDeliveryMode() ? ' (persistent)' : ' (non-persistent)'), $c->getDeliveryMode()),
129-
$prefix.'exchangeName' => $c->getExchangeName(),
130-
$prefix.'isRedelivery' => $c->isRedelivery(),
131-
$prefix.'contentType' => $c->getContentType(),
132-
$prefix.'contentEncoding' => $c->getContentEncoding(),
133-
$prefix.'type' => $c->getType(),
134-
$prefix.'timestamp' => $c->getTimeStamp(),
172+
$prefix.'delivery_tag' => $c->getDeliveryTag(),
173+
$prefix.'is_redelivery' => $c->isRedelivery(),
174+
$prefix.'exchange_name' => $c->getExchangeName(),
175+
$prefix.'routing_key' => $c->getRoutingKey(),
176+
$prefix.'content_type' => $c->getContentType(),
177+
$prefix.'content_encoding' => $c->getContentEncoding(),
178+
$prefix.'headers' => $c->getHeaders(),
179+
$prefix.'delivery_mode' => $deliveryMode,
135180
$prefix.'priority' => $c->getPriority(),
181+
$prefix.'correlation_id' => $c->getCorrelationId(),
182+
$prefix.'reply_to' => $c->getReplyTo(),
136183
$prefix.'expiration' => $c->getExpiration(),
137-
$prefix.'userId' => $c->getUserId(),
138-
$prefix.'appId' => $c->getAppId(),
139-
$prefix.'messageId' => $c->getMessageId(),
140-
$prefix.'replyTo' => $c->getReplyTo(),
141-
$prefix.'correlationId' => $c->getCorrelationId(),
142-
$prefix.'headers' => $c->getHeaders(),
184+
$prefix.'message_id' => $c->getMessageId(),
185+
$prefix.'timestamp' => $c->getTimeStamp(),
186+
$prefix.'type' => $c->getType(),
187+
$prefix.'user_id' => $c->getUserId(),
188+
$prefix.'app_id' => $c->getAppId(),
143189
);
144190

145191
return $a;

0 commit comments

Comments
 (0)