Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5977769
AmqpCaster.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
AmqpCaster.php
View Options
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
Symfony\Component\VarDumper\Caster
;
use
Symfony\Component\VarDumper\Cloner\Stub
;
/**
* Casts Amqp related classes to array representation.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @final
*/
class
AmqpCaster
{
private
const
FLAGS
=
[
\AMQP_DURABLE
=>
'AMQP_DURABLE'
,
\AMQP_PASSIVE
=>
'AMQP_PASSIVE'
,
\AMQP_EXCLUSIVE
=>
'AMQP_EXCLUSIVE'
,
\AMQP_AUTODELETE
=>
'AMQP_AUTODELETE'
,
\AMQP_INTERNAL
=>
'AMQP_INTERNAL'
,
\AMQP_NOLOCAL
=>
'AMQP_NOLOCAL'
,
\AMQP_AUTOACK
=>
'AMQP_AUTOACK'
,
\AMQP_IFEMPTY
=>
'AMQP_IFEMPTY'
,
\AMQP_IFUNUSED
=>
'AMQP_IFUNUSED'
,
\AMQP_MANDATORY
=>
'AMQP_MANDATORY'
,
\AMQP_IMMEDIATE
=>
'AMQP_IMMEDIATE'
,
\AMQP_MULTIPLE
=>
'AMQP_MULTIPLE'
,
\AMQP_NOWAIT
=>
'AMQP_NOWAIT'
,
\AMQP_REQUEUE
=>
'AMQP_REQUEUE'
,
];
private
const
EXCHANGE_TYPES
=
[
\AMQP_EX_TYPE_DIRECT
=>
'AMQP_EX_TYPE_DIRECT'
,
\AMQP_EX_TYPE_FANOUT
=>
'AMQP_EX_TYPE_FANOUT'
,
\AMQP_EX_TYPE_TOPIC
=>
'AMQP_EX_TYPE_TOPIC'
,
\AMQP_EX_TYPE_HEADERS
=>
'AMQP_EX_TYPE_HEADERS'
,
];
public
static
function
castConnection
(
\AMQPConnection
$c
,
array
$a
,
Stub
$stub
,
bool
$isNested
):
array
{
$prefix
=
Caster
::
PREFIX_VIRTUAL
;
$a
+=
[
$prefix
.
'is_connected'
=>
$c
->
isConnected
(),
];
// Recent version of the extension already expose private properties
if
(
isset
(
$a
[
"
\x
00AMQPConnection
\x
00login"
]))
{
return
$a
;
}
// BC layer in the amqp lib
if
(
method_exists
(
$c
,
'getReadTimeout'
))
{
$timeout
=
$c
->
getReadTimeout
();
}
else
{
$timeout
=
$c
->
getTimeout
();
}
$a
+=
[
$prefix
.
'is_connected'
=>
$c
->
isConnected
(),
$prefix
.
'login'
=>
$c
->
getLogin
(),
$prefix
.
'password'
=>
$c
->
getPassword
(),
$prefix
.
'host'
=>
$c
->
getHost
(),
$prefix
.
'vhost'
=>
$c
->
getVhost
(),
$prefix
.
'port'
=>
$c
->
getPort
(),
$prefix
.
'read_timeout'
=>
$timeout
,
];
return
$a
;
}
public
static
function
castChannel
(
\AMQPChannel
$c
,
array
$a
,
Stub
$stub
,
bool
$isNested
):
array
{
$prefix
=
Caster
::
PREFIX_VIRTUAL
;
$a
+=
[
$prefix
.
'is_connected'
=>
$c
->
isConnected
(),
$prefix
.
'channel_id'
=>
$c
->
getChannelId
(),
];
// Recent version of the extension already expose private properties
if
(
isset
(
$a
[
"
\x
00AMQPChannel
\x
00connection"
]))
{
return
$a
;
}
$a
+=
[
$prefix
.
'connection'
=>
$c
->
getConnection
(),
$prefix
.
'prefetch_size'
=>
$c
->
getPrefetchSize
(),
$prefix
.
'prefetch_count'
=>
$c
->
getPrefetchCount
(),
];
return
$a
;
}
public
static
function
castQueue
(
\AMQPQueue
$c
,
array
$a
,
Stub
$stub
,
bool
$isNested
):
array
{
$prefix
=
Caster
::
PREFIX_VIRTUAL
;
$a
+=
[
$prefix
.
'flags'
=>
self
::
extractFlags
(
$c
->
getFlags
()),
];
// Recent version of the extension already expose private properties
if
(
isset
(
$a
[
"
\x
00AMQPQueue
\x
00name"
]))
{
return
$a
;
}
$a
+=
[
$prefix
.
'connection'
=>
$c
->
getConnection
(),
$prefix
.
'channel'
=>
$c
->
getChannel
(),
$prefix
.
'name'
=>
$c
->
getName
(),
$prefix
.
'arguments'
=>
$c
->
getArguments
(),
];
return
$a
;
}
public
static
function
castExchange
(
\AMQPExchange
$c
,
array
$a
,
Stub
$stub
,
bool
$isNested
):
array
{
$prefix
=
Caster
::
PREFIX_VIRTUAL
;
$a
+=
[
$prefix
.
'flags'
=>
self
::
extractFlags
(
$c
->
getFlags
()),
];
$type
=
isset
(
self
::
EXCHANGE_TYPES
[
$c
->
getType
()])
?
new
ConstStub
(
self
::
EXCHANGE_TYPES
[
$c
->
getType
()],
$c
->
getType
())
:
$c
->
getType
();
// Recent version of the extension already expose private properties
if
(
isset
(
$a
[
"
\x
00AMQPExchange
\x
00name"
]))
{
$a
[
"
\x
00AMQPExchange
\x
00type"
]
=
$type
;
return
$a
;
}
$a
+=
[
$prefix
.
'connection'
=>
$c
->
getConnection
(),
$prefix
.
'channel'
=>
$c
->
getChannel
(),
$prefix
.
'name'
=>
$c
->
getName
(),
$prefix
.
'type'
=>
$type
,
$prefix
.
'arguments'
=>
$c
->
getArguments
(),
];
return
$a
;
}
public
static
function
castEnvelope
(
\AMQPEnvelope
$c
,
array
$a
,
Stub
$stub
,
bool
$isNested
,
int
$filter
=
0
):
array
{
$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
[
"
\x
00AMQPEnvelope
\x
00body"
]))
{
$a
[
"
\0
AMQPEnvelope
\0
delivery_mode"
]
=
$deliveryMode
;
return
$a
;
}
if
(!(
$filter
&
Caster
::
EXCLUDE_VERBOSE
))
{
$a
+=
[
$prefix
.
'body'
=>
$c
->
getBody
()];
}
$a
+=
[
$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
.
'message_id'
=>
$c
->
getMessageId
(),
$prefix
.
'timestamp'
=>
$c
->
getTimeStamp
(),
$prefix
.
'type'
=>
$c
->
getType
(),
$prefix
.
'user_id'
=>
$c
->
getUserId
(),
$prefix
.
'app_id'
=>
$c
->
getAppId
(),
];
return
$a
;
}
private
static
function
extractFlags
(
int
$flags
):
ConstStub
{
$flagsArray
=
[];
foreach
(
self
::
FLAGS
as
$value
=>
$name
)
{
if
(
$flags
&
$value
)
{
$flagsArray
[]
=
$name
;
}
}
if
(!
$flagsArray
)
{
$flagsArray
=
[
'AMQP_NOPARAM'
];
}
return
new
ConstStub
(
implode
(
'|'
,
$flagsArray
),
$flags
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 20:05 (3 d, 6 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0c/a1/6aa9342c4bac2e6a6ce69c0e8564
Default Alt Text
AmqpCaster.php (6 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment