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

Skip to content

Commit 11e7a66

Browse files
[VarDumper] Make use of Caster::PREFIX_* consts
1 parent 75c8a2b commit 11e7a66

File tree

10 files changed

+134
-122
lines changed

10 files changed

+134
-122
lines changed

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

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class AmqpCaster
4646

4747
public static function castConnection(\AMQPConnection $c, array $a, Stub $stub, $isNested)
4848
{
49-
$prefix = "\0~\0";
49+
$p = Caster::PREFIX_VIRTUAL;
5050

5151
// BC layer in the ampq lib
5252
if (method_exists($c, 'getReadTimeout')) {
@@ -56,87 +56,90 @@ public static function castConnection(\AMQPConnection $c, array $a, Stub $stub,
5656
}
5757

5858
$a += array(
59-
$prefix.'isConnected' => $c->isConnected(),
60-
$prefix.'login' => $c->getLogin(),
61-
$prefix.'password' => $c->getPassword(),
62-
$prefix.'host' => $c->getHost(),
63-
$prefix.'port' => $c->getPort(),
64-
$prefix.'vhost' => $c->getVhost(),
65-
$prefix.'readTimeout' => $timeout,
59+
$p.'isConnected' => $c->isConnected(),
60+
$p.'login' => $c->getLogin(),
61+
$p.'password' => $c->getPassword(),
62+
$p.'host' => $c->getHost(),
63+
$p.'port' => $c->getPort(),
64+
$p.'vhost' => $c->getVhost(),
65+
$p.'readTimeout' => $timeout,
6666
);
6767

6868
return $a;
6969
}
7070

7171
public static function castChannel(\AMQPChannel $c, array $a, Stub $stub, $isNested)
7272
{
73-
$prefix = "\0~\0";
73+
$p = Caster::PREFIX_VIRTUAL;
7474

7575
$a += array(
76-
$prefix.'isConnected' => $c->isConnected(),
77-
$prefix.'channelId' => $c->getChannelId(),
78-
$prefix.'prefetchSize' => $c->getPrefetchSize(),
79-
$prefix.'prefetchCount' => $c->getPrefetchCount(),
80-
$prefix.'connection' => $c->getConnection(),
76+
$p.'isConnected' => $c->isConnected(),
77+
$p.'channelId' => $c->getChannelId(),
78+
$p.'prefetchSize' => $c->getPrefetchSize(),
79+
$p.'prefetchCount' => $c->getPrefetchCount(),
80+
$p.'connection' => $c->getConnection(),
8181
);
8282

8383
return $a;
8484
}
8585

8686
public static function castQueue(\AMQPQueue $c, array $a, Stub $stub, $isNested)
8787
{
88-
$prefix = "\0~\0";
88+
$p = Caster::PREFIX_VIRTUAL;
8989

9090
$a += array(
91-
$prefix.'name' => $c->getName(),
92-
$prefix.'flags' => self::extractFlags($c->getFlags()),
93-
$prefix.'arguments' => $c->getArguments(),
94-
$prefix.'connection' => $c->getConnection(),
95-
$prefix.'channel' => $c->getChannel(),
91+
$p.'name' => $c->getName(),
92+
$p.'flags' => self::extractFlags($c->getFlags()),
93+
$p.'arguments' => $c->getArguments(),
94+
$p.'connection' => $c->getConnection(),
95+
$p.'channel' => $c->getChannel(),
9696
);
9797

9898
return $a;
9999
}
100100

101101
public static function castExchange(\AMQPExchange $c, array $a, Stub $stub, $isNested)
102102
{
103-
$prefix = "\0~\0";
103+
$p = Caster::PREFIX_VIRTUAL;
104104

105105
$a += array(
106-
$prefix.'name' => $c->getName(),
107-
$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(),
111-
$prefix.'connection' => $c->getConnection(),
106+
$p.'name' => $c->getName(),
107+
$p.'flags' => self::extractFlags($c->getFlags()),
108+
$p.'type' => isset(self::$exchangeTypes[$c->getType()]) ? new ConstStub(self::$exchangeTypes[$c->getType()], $c->getType()) : $c->getType(),
109+
$p.'arguments' => $c->getArguments(),
110+
$p.'channel' => $c->getChannel(),
111+
$p.'connection' => $c->getConnection(),
112112
);
113113

114114
return $a;
115115
}
116116

117-
public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, $isNested)
117+
public static function castEnvelope(\AMQPEnvelope $c, array $a, Stub $stub, $isNested, $filter = 0)
118118
{
119-
$prefix = "\0~\0";
119+
$p = Caster::PREFIX_VIRTUAL;
120+
121+
if (!($filter & Caster::EXCLUDE_VERBOSE)) {
122+
$a += array($p.'body' => $c->getBody());
123+
}
120124

121125
$a += array(
122-
$prefix.'body' => $c->getBody(),
123-
$prefix.'routingKey' => $c->getRoutingKey(),
124-
$prefix.'deliveryTag' => $c->getDeliveryTag(),
125-
$prefix.'deliveryMode' => new ConstStub($c->getDeliveryMode().(2 === $c->getDeliveryMode() ? ' (persistent)' : ' (non-persistent)'), $c->getDeliveryMode()),
126-
$prefix.'exchangeName' => $c->getExchangeName(),
127-
$prefix.'isRedelivery' => $c->isRedelivery(),
128-
$prefix.'contentType' => $c->getContentType(),
129-
$prefix.'contentEncoding' => $c->getContentEncoding(),
130-
$prefix.'type' => $c->getType(),
131-
$prefix.'timestamp' => $c->getTimestamp(),
132-
$prefix.'priority' => $c->getPriority(),
133-
$prefix.'expiration' => $c->getExpiration(),
134-
$prefix.'userId' => $c->getUserId(),
135-
$prefix.'appId' => $c->getAppId(),
136-
$prefix.'messageId' => $c->getMessageId(),
137-
$prefix.'replyTo' => $c->getReplyTo(),
138-
$prefix.'correlationId' => $c->getCorrelationId(),
139-
$prefix.'headers' => $c->getHeaders(),
126+
$p.'routingKey' => $c->getRoutingKey(),
127+
$p.'deliveryTag' => $c->getDeliveryTag(),
128+
$p.'deliveryMode' => new ConstStub($c->getDeliveryMode().(2 === $c->getDeliveryMode() ? ' (persistent)' : ' (non-persistent)'), $c->getDeliveryMode()),
129+
$p.'exchangeName' => $c->getExchangeName(),
130+
$p.'isRedelivery' => $c->isRedelivery(),
131+
$p.'contentType' => $c->getContentType(),
132+
$p.'contentEncoding' => $c->getContentEncoding(),
133+
$p.'type' => $c->getType(),
134+
$p.'timestamp' => $c->getTimestamp(),
135+
$p.'priority' => $c->getPriority(),
136+
$p.'expiration' => $c->getExpiration(),
137+
$p.'userId' => $c->getUserId(),
138+
$p.'appId' => $c->getAppId(),
139+
$p.'messageId' => $c->getMessageId(),
140+
$p.'replyTo' => $c->getReplyTo(),
141+
$p.'correlationId' => $c->getCorrelationId(),
142+
$p.'headers' => $c->getHeaders(),
140143
);
141144

142145
return $a;

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@ class Caster
2929
const EXCLUDE_NOT_IMPORTANT = 256;
3030
const EXCLUDE_STRICT = 512;
3131

32+
const PREFIX_VIRTUAL = "\0~\0";
33+
const PREFIX_DYNAMIC = "\0+\0";
34+
const PREFIX_PROTECTED = "\0*\0";
35+
36+
/**
37+
* Casts objects to arrays and adds the dynamic property prefix.
38+
*
39+
* @param object $obj The object to cast.
40+
* @param ReflectionClass $reflector The class reflector to use for inspecting the object definition.
41+
*
42+
* @return array The array-cast of the object, with prefixed dynamic properties.
43+
*/
44+
public static function castObject($obj, \ReflectionClass $reflector)
45+
{
46+
if ($reflector->hasMethod('__debugInfo')) {
47+
$a = $obj->__debugInfo();
48+
} else {
49+
$a = (array) $obj;
50+
}
51+
52+
if ($a) {
53+
$p = array_keys($a);
54+
foreach ($p as $i => $k) {
55+
if (!isset($k[0]) || ("\0" !== $k[0] && !$reflector->hasProperty($k))) {
56+
$p[$i] = self::PREFIX_DYNAMIC.$k;
57+
}
58+
}
59+
$a = array_combine($p, $a);
60+
}
61+
62+
return $a;
63+
}
64+
3265
/**
3366
* Filters out the specified properties.
3467
*

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class DOMCaster
6363

6464
public static function castException(\DOMException $e, array $a, Stub $stub, $isNested)
6565
{
66-
if (isset($a["\0*\0code"], self::$errorCodes[$a["\0*\0code"]])) {
67-
$a["\0*\0code"] = new ConstStub(self::$errorCodes[$a["\0*\0code"]], $a["\0*\0code"]);
66+
$k = Caster::PREFIX_PROTECTED.'code';
67+
if (isset($a[$k], self::$errorCodes[$a[$k]])) {
68+
$a[$k] = new ConstStub(self::$errorCodes[$a[$k]], $a[$k]);
6869
}
6970

7071
return $a;
@@ -82,8 +83,8 @@ public static function castLength($dom, array $a, Stub $stub, $isNested)
8283
public static function castImplementation($dom, array $a, Stub $stub, $isNested)
8384
{
8485
$a += array(
85-
"\0~\0Core" => '1.0',
86-
"\0~\0XML" => '2.0',
86+
Caster::PREFIX_VIRTUAL.'Core' => '1.0',
87+
Caster::PREFIX_VIRTUAL.'XML' => '2.0',
8788
);
8889

8990
return $a;
@@ -129,11 +130,8 @@ public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub
129130
return $a;
130131
}
131132

132-
public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $isNested)
133+
public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $isNested, $filter = 0)
133134
{
134-
$formatOutput = $dom->formatOutput;
135-
$dom->formatOutput = true;
136-
137135
$a += array(
138136
'doctype' => $dom->doctype,
139137
'implementation' => $dom->implementation,
@@ -148,16 +146,20 @@ public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $is
148146
'strictErrorChecking' => $dom->strictErrorChecking,
149147
'documentURI' => $dom->documentURI,
150148
'config' => $dom->config,
151-
'formatOutput' => $formatOutput,
149+
'formatOutput' => $dom->formatOutput,
152150
'validateOnParse' => $dom->validateOnParse,
153151
'resolveExternals' => $dom->resolveExternals,
154152
'preserveWhiteSpace' => $dom->preserveWhiteSpace,
155153
'recover' => $dom->recover,
156154
'substituteEntities' => $dom->substituteEntities,
157-
"\0~\0xml" => $dom->saveXML(),
158155
);
159156

160-
$dom->formatOutput = $formatOutput;
157+
if (!($filter & Caster::EXCLUDE_VERBOSE)) {
158+
$formatOutput = $dom->formatOutput;
159+
$dom->formatOutput = true;
160+
$a += array(Caster::PREFIX_VIRTUAL.'xml' => $dom->saveXML());
161+
$dom->formatOutput = $formatOutput;
162+
}
161163

162164
return $a;
163165
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ class MongoCaster
2222
{
2323
public static function castCursor(\MongoCursorInterface $cursor, array $a, Stub $stub, $isNested)
2424
{
25-
$prefix = "\0~\0";
26-
2725
if ($info = $cursor->info()) {
2826
foreach ($info as $k => $v) {
29-
$a[$prefix.$k] = $v;
27+
$a[Caster::PREFIX_VIRTUAL.$k] = $v;
3028
}
3129
}
32-
$a[$prefix.'dead'] = $cursor->dead();
30+
$a[Caster::PREFIX_VIRTUAL.'dead'] = $cursor->dead();
3331

3432
return $a;
3533
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ public static function castPdo(\PDO $c, array $a, Stub $stub, $isNested)
7878
}
7979
}
8080

81-
$m = "\0~\0";
81+
$p = Caster::PREFIX_VIRTUAL;
8282
$a += array(
83-
$m.'inTransaction' => method_exists($c, 'inTransaction'),
84-
$m.'errorInfo' => $c->errorInfo(),
85-
$m.'attributes' => $attr,
83+
$p.'inTransaction' => method_exists($c, 'inTransaction'),
84+
$p.'errorInfo' => $c->errorInfo(),
85+
$p.'attributes' => $attr,
8686
);
8787

88-
if ($a[$m.'inTransaction']) {
89-
$a[$m.'inTransaction'] = $c->inTransaction();
88+
if ($a[$p.'inTransaction']) {
89+
$a[$p.'inTransaction'] = $c->inTransaction();
9090
} else {
91-
unset($a[$m.'inTransaction']);
91+
unset($a[$p.'inTransaction']);
9292
}
9393

94-
if (!isset($a[$m.'errorInfo'][1], $a[$m.'errorInfo'][2])) {
95-
unset($a[$m.'errorInfo']);
94+
if (!isset($a[$p.'errorInfo'][1], $a[$p.'errorInfo'][2])) {
95+
unset($a[$p.'errorInfo']);
9696
}
9797

9898
$c->setAttribute(\PDO::ATTR_ERRMODE, $errmode);
@@ -102,11 +102,11 @@ public static function castPdo(\PDO $c, array $a, Stub $stub, $isNested)
102102

103103
public static function castPdoStatement(\PDOStatement $c, array $a, Stub $stub, $isNested)
104104
{
105-
$m = "\0~\0";
106-
$a[$m.'errorInfo'] = $c->errorInfo();
105+
$p = Caster::PREFIX_VIRTUAL;
106+
$a[$p.'errorInfo'] = $c->errorInfo();
107107

108-
if (!isset($a[$m.'errorInfo'][1], $a[$m.'errorInfo'][2])) {
109-
unset($a[$m.'errorInfo']);
108+
if (!isset($a[$p.'errorInfo'][1], $a[$p.'errorInfo'][2])) {
109+
unset($a[$p.'errorInfo']);
110110
}
111111

112112
return $a;

0 commit comments

Comments
 (0)