comparison vendor/symfony/var-dumper/Caster/AmqpCaster.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\VarDumper\Caster;
13
14 use Symfony\Component\VarDumper\Cloner\Stub;
15
16 /**
17 * Casts Amqp related classes to array representation.
18 *
19 * @author Grégoire Pineau <lyrixx@lyrixx.info>
20 */
21 class AmqpCaster
22 {
23 private static $flags = array(
24 AMQP_DURABLE => 'AMQP_DURABLE',
25 AMQP_PASSIVE => 'AMQP_PASSIVE',
26 AMQP_EXCLUSIVE => 'AMQP_EXCLUSIVE',
27 AMQP_AUTODELETE => 'AMQP_AUTODELETE',
28 AMQP_INTERNAL => 'AMQP_INTERNAL',
29 AMQP_NOLOCAL => 'AMQP_NOLOCAL',
30 AMQP_AUTOACK => 'AMQP_AUTOACK',
31 AMQP_IFEMPTY => 'AMQP_IFEMPTY',
32 AMQP_IFUNUSED => 'AMQP_IFUNUSED',
33 AMQP_MANDATORY => 'AMQP_MANDATORY',
34 AMQP_IMMEDIATE => 'AMQP_IMMEDIATE',
35 AMQP_MULTIPLE => 'AMQP_MULTIPLE',
36 AMQP_NOWAIT => 'AMQP_NOWAIT',
37 AMQP_REQUEUE => 'AMQP_REQUEUE',
38 );
39
40 private static $exchangeTypes = array(
41 AMQP_EX_TYPE_DIRECT => 'AMQP_EX_TYPE_DIRECT',
42 AMQP_EX_TYPE_FANOUT => 'AMQP_EX_TYPE_FANOUT',
43 AMQP_EX_TYPE_TOPIC => 'AMQP_EX_TYPE_TOPIC',
44 AMQP_EX_TYPE_HEADERS => 'AMQP_EX_TYPE_HEADERS',
45 );
46
47 public static function castConnection(\AMQPConnection $c, array $a, Stub $stub, $isNested)
48 {
49 $prefix = Caster::PREFIX_VIRTUAL;
50
51 $a += array(
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
60 // BC layer in the amqp lib
61 if (method_exists($c, 'getReadTimeout')) {
62 $timeout = $c->getReadTimeout();
63 } else {
64 $timeout = $c->getTimeout();
65 }
66
67 $a += array(
68 $prefix.'is_connected' => $c->isConnected(),
69 $prefix.'login' => $c->getLogin(),
70 $prefix.'password' => $c->getPassword(),
71 $prefix.'host' => $c->getHost(),
72 $prefix.'vhost' => $c->getVhost(),
73 $prefix.'port' => $c->getPort(),
74 $prefix.'read_timeout' => $timeout,
75 );
76
77 return $a;
78 }
79
80 public static function castChannel(\AMQPChannel $c, array $a, Stub $stub, $isNested)
81 {
82 $prefix = Caster::PREFIX_VIRTUAL;
83
84 $a += array(
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(
95 $prefix.'connection' => $c->getConnection(),
96 $prefix.'prefetch_size' => $c->getPrefetchSize(),
97 $prefix.'prefetch_count' => $c->getPrefetchCount(),
98 );
99
100 return $a;
101 }
102
103 public static function castQueue(\AMQPQueue $c, array $a, Stub $stub, $isNested)
104 {
105 $prefix = Caster::PREFIX_VIRTUAL;
106
107 $a += array(
108 $prefix.'flags' => self::extractFlags($c->getFlags()),
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(
117 $prefix.'connection' => $c->getConnection(),
118 $prefix.'channel' => $c->getChannel(),
119 $prefix.'name' => $c->getName(),
120 $prefix.'arguments' => $c->getArguments(),
121 );
122
123 return $a;
124 }
125
126 public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, $isNested)
127 {
128 $prefix = Caster::PREFIX_VIRTUAL;
129
130 $a += array(
131 $prefix.'flags' => self::extractFlags($c->getFlags()),
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(
144 $prefix.'connection' => $c->getConnection(),
145 $prefix.'channel' => $c->getChannel(),
146 $prefix.'name' => $c->getName(),
147 $prefix.'type' => $type,
148 $prefix.'arguments' => $c->getArguments(),
149 );
150
151 return $a;
152 }
153
154 public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, $isNested, $filter = 0)
155 {
156 $prefix = Caster::PREFIX_VIRTUAL;
157
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
167 if (!($filter & Caster::EXCLUDE_VERBOSE)) {
168 $a += array($prefix.'body' => $c->getBody());
169 }
170
171 $a += array(
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,
180 $prefix.'priority' => $c->getPriority(),
181 $prefix.'correlation_id' => $c->getCorrelationId(),
182 $prefix.'reply_to' => $c->getReplyTo(),
183 $prefix.'expiration' => $c->getExpiration(),
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(),
189 );
190
191 return $a;
192 }
193
194 private static function extractFlags($flags)
195 {
196 $flagsArray = array();
197
198 foreach (self::$flags as $value => $name) {
199 if ($flags & $value) {
200 $flagsArray[] = $name;
201 }
202 }
203
204 if (!$flagsArray) {
205 $flagsArray = array('AMQP_NOPARAM');
206 }
207
208 return new ConstStub(implode('|', $flagsArray), $flags);
209 }
210 }