Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\VarDumper\Caster; Chris@0: Chris@0: use Symfony\Component\VarDumper\Cloner\Stub; Chris@0: Chris@0: /** Chris@0: * Casts Amqp related classes to array representation. Chris@0: * Chris@0: * @author Grégoire Pineau Chris@0: */ Chris@0: class AmqpCaster Chris@0: { Chris@17: private static $flags = [ Chris@0: AMQP_DURABLE => 'AMQP_DURABLE', Chris@0: AMQP_PASSIVE => 'AMQP_PASSIVE', Chris@0: AMQP_EXCLUSIVE => 'AMQP_EXCLUSIVE', Chris@0: AMQP_AUTODELETE => 'AMQP_AUTODELETE', Chris@0: AMQP_INTERNAL => 'AMQP_INTERNAL', Chris@0: AMQP_NOLOCAL => 'AMQP_NOLOCAL', Chris@0: AMQP_AUTOACK => 'AMQP_AUTOACK', Chris@0: AMQP_IFEMPTY => 'AMQP_IFEMPTY', Chris@0: AMQP_IFUNUSED => 'AMQP_IFUNUSED', Chris@0: AMQP_MANDATORY => 'AMQP_MANDATORY', Chris@0: AMQP_IMMEDIATE => 'AMQP_IMMEDIATE', Chris@0: AMQP_MULTIPLE => 'AMQP_MULTIPLE', Chris@0: AMQP_NOWAIT => 'AMQP_NOWAIT', Chris@0: AMQP_REQUEUE => 'AMQP_REQUEUE', Chris@17: ]; Chris@0: Chris@17: private static $exchangeTypes = [ Chris@0: AMQP_EX_TYPE_DIRECT => 'AMQP_EX_TYPE_DIRECT', Chris@0: AMQP_EX_TYPE_FANOUT => 'AMQP_EX_TYPE_FANOUT', Chris@0: AMQP_EX_TYPE_TOPIC => 'AMQP_EX_TYPE_TOPIC', Chris@0: AMQP_EX_TYPE_HEADERS => 'AMQP_EX_TYPE_HEADERS', Chris@17: ]; Chris@0: Chris@0: public static function castConnection(\AMQPConnection $c, array $a, Stub $stub, $isNested) Chris@0: { Chris@0: $prefix = Caster::PREFIX_VIRTUAL; Chris@0: Chris@17: $a += [ Chris@0: $prefix.'is_connected' => $c->isConnected(), Chris@17: ]; Chris@0: Chris@0: // Recent version of the extension already expose private properties Chris@0: if (isset($a["\x00AMQPConnection\x00login"])) { Chris@0: return $a; Chris@0: } Chris@0: Chris@0: // BC layer in the amqp lib Chris@0: if (method_exists($c, 'getReadTimeout')) { Chris@0: $timeout = $c->getReadTimeout(); Chris@0: } else { Chris@0: $timeout = $c->getTimeout(); Chris@0: } Chris@0: Chris@17: $a += [ Chris@0: $prefix.'is_connected' => $c->isConnected(), Chris@0: $prefix.'login' => $c->getLogin(), Chris@0: $prefix.'password' => $c->getPassword(), Chris@0: $prefix.'host' => $c->getHost(), Chris@0: $prefix.'vhost' => $c->getVhost(), Chris@0: $prefix.'port' => $c->getPort(), Chris@0: $prefix.'read_timeout' => $timeout, Chris@17: ]; Chris@0: Chris@0: return $a; Chris@0: } Chris@0: Chris@0: public static function castChannel(\AMQPChannel $c, array $a, Stub $stub, $isNested) Chris@0: { Chris@0: $prefix = Caster::PREFIX_VIRTUAL; Chris@0: Chris@17: $a += [ Chris@0: $prefix.'is_connected' => $c->isConnected(), Chris@0: $prefix.'channel_id' => $c->getChannelId(), Chris@17: ]; Chris@0: Chris@0: // Recent version of the extension already expose private properties Chris@0: if (isset($a["\x00AMQPChannel\x00connection"])) { Chris@0: return $a; Chris@0: } Chris@0: Chris@17: $a += [ Chris@0: $prefix.'connection' => $c->getConnection(), Chris@0: $prefix.'prefetch_size' => $c->getPrefetchSize(), Chris@0: $prefix.'prefetch_count' => $c->getPrefetchCount(), Chris@17: ]; Chris@0: Chris@0: return $a; Chris@0: } Chris@0: Chris@0: public static function castQueue(\AMQPQueue $c, array $a, Stub $stub, $isNested) Chris@0: { Chris@0: $prefix = Caster::PREFIX_VIRTUAL; Chris@0: Chris@17: $a += [ Chris@0: $prefix.'flags' => self::extractFlags($c->getFlags()), Chris@17: ]; Chris@0: Chris@0: // Recent version of the extension already expose private properties Chris@0: if (isset($a["\x00AMQPQueue\x00name"])) { Chris@0: return $a; Chris@0: } Chris@0: Chris@17: $a += [ Chris@0: $prefix.'connection' => $c->getConnection(), Chris@0: $prefix.'channel' => $c->getChannel(), Chris@0: $prefix.'name' => $c->getName(), Chris@0: $prefix.'arguments' => $c->getArguments(), Chris@17: ]; Chris@0: Chris@0: return $a; Chris@0: } Chris@0: Chris@0: public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, $isNested) Chris@0: { Chris@0: $prefix = Caster::PREFIX_VIRTUAL; Chris@0: Chris@17: $a += [ Chris@0: $prefix.'flags' => self::extractFlags($c->getFlags()), Chris@17: ]; Chris@0: Chris@0: $type = isset(self::$exchangeTypes[$c->getType()]) ? new ConstStub(self::$exchangeTypes[$c->getType()], $c->getType()) : $c->getType(); Chris@0: Chris@0: // Recent version of the extension already expose private properties Chris@0: if (isset($a["\x00AMQPExchange\x00name"])) { Chris@0: $a["\x00AMQPExchange\x00type"] = $type; Chris@0: Chris@0: return $a; Chris@0: } Chris@0: Chris@17: $a += [ Chris@0: $prefix.'connection' => $c->getConnection(), Chris@0: $prefix.'channel' => $c->getChannel(), Chris@0: $prefix.'name' => $c->getName(), Chris@0: $prefix.'type' => $type, Chris@0: $prefix.'arguments' => $c->getArguments(), Chris@17: ]; Chris@0: Chris@0: return $a; Chris@0: } Chris@0: Chris@0: public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, $isNested, $filter = 0) Chris@0: { Chris@0: $prefix = Caster::PREFIX_VIRTUAL; Chris@0: Chris@0: $deliveryMode = new ConstStub($c->getDeliveryMode().(2 === $c->getDeliveryMode() ? ' (persistent)' : ' (non-persistent)'), $c->getDeliveryMode()); Chris@0: Chris@0: // Recent version of the extension already expose private properties Chris@0: if (isset($a["\x00AMQPEnvelope\x00body"])) { Chris@0: $a["\0AMQPEnvelope\0delivery_mode"] = $deliveryMode; Chris@0: Chris@0: return $a; Chris@0: } Chris@0: Chris@0: if (!($filter & Caster::EXCLUDE_VERBOSE)) { Chris@17: $a += [$prefix.'body' => $c->getBody()]; Chris@0: } Chris@0: Chris@17: $a += [ Chris@0: $prefix.'delivery_tag' => $c->getDeliveryTag(), Chris@0: $prefix.'is_redelivery' => $c->isRedelivery(), Chris@0: $prefix.'exchange_name' => $c->getExchangeName(), Chris@0: $prefix.'routing_key' => $c->getRoutingKey(), Chris@0: $prefix.'content_type' => $c->getContentType(), Chris@0: $prefix.'content_encoding' => $c->getContentEncoding(), Chris@0: $prefix.'headers' => $c->getHeaders(), Chris@0: $prefix.'delivery_mode' => $deliveryMode, Chris@0: $prefix.'priority' => $c->getPriority(), Chris@0: $prefix.'correlation_id' => $c->getCorrelationId(), Chris@0: $prefix.'reply_to' => $c->getReplyTo(), Chris@0: $prefix.'expiration' => $c->getExpiration(), Chris@0: $prefix.'message_id' => $c->getMessageId(), Chris@0: $prefix.'timestamp' => $c->getTimeStamp(), Chris@0: $prefix.'type' => $c->getType(), Chris@0: $prefix.'user_id' => $c->getUserId(), Chris@0: $prefix.'app_id' => $c->getAppId(), Chris@17: ]; Chris@0: Chris@0: return $a; Chris@0: } Chris@0: Chris@0: private static function extractFlags($flags) Chris@0: { Chris@17: $flagsArray = []; Chris@0: Chris@0: foreach (self::$flags as $value => $name) { Chris@0: if ($flags & $value) { Chris@0: $flagsArray[] = $name; Chris@0: } Chris@0: } Chris@0: Chris@0: if (!$flagsArray) { Chris@17: $flagsArray = ['AMQP_NOPARAM']; Chris@0: } Chris@0: Chris@0: return new ConstStub(implode('|', $flagsArray), $flags); Chris@0: } Chris@0: }