|
| 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 | +} |
0 commit comments