PHP 8.3.31
Preview: RdKafkaCaster.php Size: 4.62 KB
/home/getspomw/royalsquad.us/vendor/symfony/var-dumper/Caster/RdKafkaCaster.php

<?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 RdKafka\Conf;
use RdKafka\Exception as RdKafkaException;
use RdKafka\KafkaConsumer;
use RdKafka\Message;
use RdKafka\Metadata\Broker as BrokerMetadata;
use RdKafka\Metadata\Collection as CollectionMetadata;
use RdKafka\Metadata\Partition as PartitionMetadata;
use RdKafka\Metadata\Topic as TopicMetadata;
use RdKafka\Topic;
use RdKafka\TopicConf;
use RdKafka\TopicPartition;
use Symfony\Component\VarDumper\Cloner\Stub;

/**
 * Casts RdKafka related classes to array representation.
 *
 * @author Romain Neutron <imprec@gmail.com>
 */
class RdKafkaCaster
{
    public static function castKafkaConsumer(KafkaConsumer $c, array $a, Stub $stub, bool $isNested): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        try {
            $assignment = $c->getAssignment();
        } catch (RdKafkaException) {
            $assignment = [];
        }

        $a += [
            $prefix.'subscription' => $c->getSubscription(),
            $prefix.'assignment' => $assignment,
        ];

        $a += self::extractMetadata($c);

        return $a;
    }

    public static function castTopic(Topic $c, array $a, Stub $stub, bool $isNested): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        $a += [
            $prefix.'name' => $c->getName(),
        ];

        return $a;
    }

    public static function castTopicPartition(TopicPartition $c, array $a): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        $a += [
            $prefix.'offset' => $c->getOffset(),
            $prefix.'partition' => $c->getPartition(),
            $prefix.'topic' => $c->getTopic(),
        ];

        return $a;
    }

    public static function castMessage(Message $c, array $a, Stub $stub, bool $isNested): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        $a += [
            $prefix.'errstr' => $c->errstr(),
        ];

        return $a;
    }

    public static function castConf(Conf $c, array $a, Stub $stub, bool $isNested): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        foreach ($c->dump() as $key => $value) {
            $a[$prefix.$key] = $value;
        }

        return $a;
    }

    public static function castTopicConf(TopicConf $c, array $a, Stub $stub, bool $isNested): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        foreach ($c->dump() as $key => $value) {
            $a[$prefix.$key] = $value;
        }

        return $a;
    }

    public static function castRdKafka(\RdKafka $c, array $a, Stub $stub, bool $isNested): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        $a += [
            $prefix.'out_q_len' => $c->getOutQLen(),
        ];

        $a += self::extractMetadata($c);

        return $a;
    }

    public static function castCollectionMetadata(CollectionMetadata $c, array $a, Stub $stub, bool $isNested): array
    {
        $a += iterator_to_array($c);

        return $a;
    }

    public static function castTopicMetadata(TopicMetadata $c, array $a, Stub $stub, bool $isNested): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        $a += [
            $prefix.'name' => $c->getTopic(),
            $prefix.'partitions' => $c->getPartitions(),
        ];

        return $a;
    }

    public static function castPartitionMetadata(PartitionMetadata $c, array $a, Stub $stub, bool $isNested): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        $a += [
            $prefix.'id' => $c->getId(),
            $prefix.'err' => $c->getErr(),
            $prefix.'leader' => $c->getLeader(),
        ];

        return $a;
    }

    public static function castBrokerMetadata(BrokerMetadata $c, array $a, Stub $stub, bool $isNested): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        $a += [
            $prefix.'id' => $c->getId(),
            $prefix.'host' => $c->getHost(),
            $prefix.'port' => $c->getPort(),
        ];

        return $a;
    }

    private static function extractMetadata(KafkaConsumer|\RdKafka $c): array
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        try {
            $m = $c->getMetadata(true, null, 500);
        } catch (RdKafkaException) {
            return [];
        }

        return [
            $prefix.'orig_broker_id' => $m->getOrigBrokerId(),
            $prefix.'orig_broker_name' => $m->getOrigBrokerName(),
            $prefix.'brokers' => $m->getBrokers(),
            $prefix.'topics' => $m->getTopics(),
        ];
    }
}

Directory Contents

Dirs: 0 × Files: 42

Name Size Perms Modified Actions
6.57 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
2.23 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
6.79 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
3.73 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
740 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
702 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
1.89 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
4.80 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
1.65 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
10.65 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
1.55 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
625 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
596 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
13.40 KB lrw-r--r-- 2026-04-26 10:19:19
Edit Download
16.06 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
5.53 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
1.04 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
659 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
749 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
949 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
637 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
8.76 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
3.29 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
2.24 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
691 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
3.49 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
5.38 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
728 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
4.62 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
5.35 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
14.79 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
2.92 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
554 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
7.83 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
2.33 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
3.51 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
759 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
615 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
668 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
548 B lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
3.31 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download
2.49 KB lrw-rw-rw- 2025-09-17 06:53:24
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).