Skip to content

Commit fc0fb08

Browse files
committed
Add a RdKafka caster to Var-Dumper
1 parent b350c80 commit fc0fb08

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 RdKafka;
15+
use RdKafka\Conf;
16+
use RdKafka\Message;
17+
use RdKafka\Topic;
18+
use RdKafka\TopicConf;
19+
use RdKafka\KafkaConsumer;
20+
use Symfony\Component\VarDumper\Cloner\Stub;
21+
22+
/**
23+
* Casts RdKafka related classes to array representation.
24+
*
25+
* @author Romain Neutron <imprec@gmail.com>
26+
*
27+
* @experimental
28+
*/
29+
class RdKafkaCaster
30+
{
31+
public static function castKafkaConsumer(KafkaConsumer $c, array $a, Stub $stub, $isNested)
32+
{
33+
$prefix = Caster::PREFIX_VIRTUAL;
34+
35+
$a += [
36+
$prefix.'subscription' => $c->getSubscription(),
37+
];
38+
39+
return $a;
40+
}
41+
42+
public static function castTopic(Topic $c, array $a, Stub $stub, $isNested)
43+
{
44+
$prefix = Caster::PREFIX_VIRTUAL;
45+
46+
$a += [
47+
$prefix.'name' => $c->getName(),
48+
];
49+
50+
return $a;
51+
}
52+
53+
public static function castMessage(Message $c, array $a, Stub $stub, $isNested)
54+
{
55+
$prefix = Caster::PREFIX_VIRTUAL;
56+
57+
$a += [
58+
$prefix.'errstr' => $c->errstr(),
59+
];
60+
61+
return $a;
62+
}
63+
64+
public static function castConf(Conf $c, array $a, Stub $stub, $isNested)
65+
{
66+
$prefix = Caster::PREFIX_VIRTUAL;
67+
68+
$conf = [];
69+
70+
foreach ($c->dump() as $key => $value) {
71+
$conf[$prefix.$key] = $value;
72+
}
73+
74+
$a += $conf;
75+
76+
return $a;
77+
}
78+
79+
public static function castTopicConf(TopicConf $c, array $a, Stub $stub, $isNested)
80+
{
81+
$prefix = Caster::PREFIX_VIRTUAL;
82+
83+
$conf = [];
84+
85+
foreach ($c->dump() as $key => $value) {
86+
$conf[$prefix.$key] = $value;
87+
}
88+
89+
$a += $conf;
90+
91+
return $a;
92+
}
93+
94+
public static function castRdKafka(\RdKafka $c, array $a, Stub $stub, $isNested)
95+
{
96+
$prefix = Caster::PREFIX_VIRTUAL;
97+
98+
$a += [
99+
$prefix.'out_q_len' => $c->getOutQLen(),
100+
];
101+
102+
return $a;
103+
}
104+
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ abstract class AbstractCloner implements ClonerInterface
160160
':persistent stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'],
161161
':stream-context' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'],
162162
':xml' => ['Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'],
163+
164+
'RdKafka' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castRdKafka'],
165+
'RdKafka\Topic' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopic'],
166+
'RdKafka\Conf' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castConf'],
167+
'RdKafka\TopicConf' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicConf'],
168+
'RdKafka\Message' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castMessage'],
169+
'RdKafka\KafkaConsumer' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castKafkaConsumer'],
163170
];
164171

165172
protected $maxItems = 2500;

0 commit comments

Comments
 (0)