<?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 WappoVendor\Symfony\Component\VarDumper\Cloner;

use WappoVendor\Symfony\Component\VarDumper\Caster\Caster;
use WappoVendor\Symfony\Component\VarDumper\Exception\ThrowingCasterException;
/**
 * AbstractCloner implements a generic caster mechanism for objects and resources.
 *
 * @author Nicolas Grekas <p@tchwork.com>
 */
abstract class AbstractCloner implements ClonerInterface
{
    public static $defaultCasters = ['__PHP_Incomplete_Class' => ['WappoVendor\Symfony\Component\VarDumper\Caster\Caster', 'castPhpIncompleteClass'], 'WappoVendor\Symfony\Component\VarDumper\Caster\CutStub' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'], 'WappoVendor\Symfony\Component\VarDumper\Caster\CutArrayStub' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'castCutArray'], 'WappoVendor\Symfony\Component\VarDumper\Caster\ConstStub' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'], 'WappoVendor\Symfony\Component\VarDumper\Caster\EnumStub' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'castEnum'], 'Fiber' => ['WappoVendor\Symfony\Component\VarDumper\Caster\FiberCaster', 'castFiber'], 'Closure' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClosure'], 'Generator' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castGenerator'], 'ReflectionType' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castType'], 'ReflectionAttribute' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castAttribute'], 'ReflectionGenerator' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castReflectionGenerator'], 'ReflectionClass' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClass'], 'ReflectionClassConstant' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClassConstant'], 'ReflectionFunctionAbstract' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castFunctionAbstract'], 'ReflectionMethod' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castMethod'], 'ReflectionParameter' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castParameter'], 'ReflectionProperty' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castProperty'], 'ReflectionReference' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castReference'], 'ReflectionExtension' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castExtension'], 'ReflectionZendExtension' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castZendExtension'], 'WappoVendor\Doctrine\Common\Persistence\ObjectManager' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'WappoVendor\Doctrine\Common\Proxy\Proxy' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castCommonProxy'], 'WappoVendor\Doctrine\ORM\Proxy\Proxy' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castOrmProxy'], 'WappoVendor\Doctrine\ORM\PersistentCollection' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castPersistentCollection'], 'WappoVendor\Doctrine\Persistence\ObjectManager' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'DOMException' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castException'], 'DOMStringList' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], 'DOMNameList' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], 'DOMImplementation' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castImplementation'], 'DOMImplementationList' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], 'DOMNode' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castNode'], 'DOMNameSpaceNode' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castNameSpaceNode'], 'DOMDocument' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocument'], 'DOMNodeList' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], 'DOMNamedNodeMap' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], 'DOMCharacterData' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castCharacterData'], 'DOMAttr' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castAttr'], 'DOMElement' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castElement'], 'DOMText' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castText'], 'DOMTypeinfo' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castTypeinfo'], 'DOMDomError' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castDomError'], 'DOMLocator' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castLocator'], 'DOMDocumentType' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocumentType'], 'DOMNotation' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castNotation'], 'DOMEntity' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castEntity'], 'DOMProcessingInstruction' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castProcessingInstruction'], 'DOMXPath' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DOMCaster', 'castXPath'], 'XMLReader' => ['WappoVendor\Symfony\Component\VarDumper\Caster\XmlReaderCaster', 'castXmlReader'], 'ErrorException' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castErrorException'], 'Exception' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castException'], 'Error' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castError'], 'WappoVendor\Symfony\Bridge\Monolog\Logger' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'WappoVendor\Symfony\Component\DependencyInjection\ContainerInterface' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'WappoVendor\Symfony\Component\EventDispatcher\EventDispatcherInterface' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'WappoVendor\Symfony\Component\HttpClient\AmpHttpClient' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'], 'WappoVendor\Symfony\Component\HttpClient\CurlHttpClient' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'], 'WappoVendor\Symfony\Component\HttpClient\NativeHttpClient' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'], 'WappoVendor\Symfony\Component\HttpClient\Response\AmpResponse' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'], 'WappoVendor\Symfony\Component\HttpClient\Response\CurlResponse' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'], 'WappoVendor\Symfony\Component\HttpClient\Response\NativeResponse' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'], 'WappoVendor\Symfony\Component\HttpFoundation\Request' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'], 'WappoVendor\Symfony\Component\Uid\Ulid' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUlid'], 'WappoVendor\Symfony\Component\Uid\Uuid' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUuid'], 'WappoVendor\Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'], 'WappoVendor\Symfony\Component\VarDumper\Caster\TraceStub' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'], 'WappoVendor\Symfony\Component\VarDumper\Caster\FrameStub' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'], 'WappoVendor\Symfony\Component\VarDumper\Cloner\AbstractCloner' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'WappoVendor\Symfony\Component\ErrorHandler\Exception\SilencedErrorContext' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'], 'WappoVendor\Imagine\Image\ImageInterface' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ImagineCaster', 'castImage'], 'WappoVendor\Ramsey\Uuid\UuidInterface' => ['WappoVendor\Symfony\Component\VarDumper\Caster\UuidCaster', 'castRamseyUuid'], 'WappoVendor\ProxyManager\Proxy\ProxyInterface' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'], 'PHPUnit_Framework_MockObject_MockObject' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'WappoVendor\PHPUnit\Framework\MockObject\MockObject' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'WappoVendor\PHPUnit\Framework\MockObject\Stub' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'WappoVendor\Prophecy\Prophecy\ProphecySubjectInterface' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'WappoVendor\Mockery\MockInterface' => ['WappoVendor\Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'], 'PDO' => ['WappoVendor\Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdo'], 'PDOStatement' => ['WappoVendor\Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdoStatement'], 'AMQPConnection' => ['WappoVendor\Symfony\Component\VarDumper\Caster\AmqpCaster', 'castConnection'], 'AMQPChannel' => ['WappoVendor\Symfony\Component\VarDumper\Caster\AmqpCaster', 'castChannel'], 'AMQPQueue' => ['WappoVendor\Symfony\Component\VarDumper\Caster\AmqpCaster', 'castQueue'], 'AMQPExchange' => ['WappoVendor\Symfony\Component\VarDumper\Caster\AmqpCaster', 'castExchange'], 'AMQPEnvelope' => ['WappoVendor\Symfony\Component\VarDumper\Caster\AmqpCaster', 'castEnvelope'], 'ArrayObject' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayObject'], 'ArrayIterator' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayIterator'], 'SplDoublyLinkedList' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'], 'SplFileInfo' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'], 'SplFileObject' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'], 'SplHeap' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'], 'SplObjectStorage' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castObjectStorage'], 'SplPriorityQueue' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'], 'OuterIterator' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castOuterIterator'], 'WeakReference' => ['WappoVendor\Symfony\Component\VarDumper\Caster\SplCaster', 'castWeakReference'], 'Redis' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedis'], 'RedisArray' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisArray'], 'RedisCluster' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisCluster'], 'DateTimeInterface' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DateCaster', 'castDateTime'], 'DateInterval' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DateCaster', 'castInterval'], 'DateTimeZone' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'], 'DatePeriod' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DateCaster', 'castPeriod'], 'GMP' => ['WappoVendor\Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'], 'MessageFormatter' => ['WappoVendor\Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'], 'NumberFormatter' => ['WappoVendor\Symfony\Component\VarDumper\Caster\IntlCaster', 'castNumberFormatter'], 'IntlTimeZone' => ['WappoVendor\Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlTimeZone'], 'IntlCalendar' => ['WappoVendor\Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlCalendar'], 'IntlDateFormatter' => ['WappoVendor\Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlDateFormatter'], 'Memcached' => ['WappoVendor\Symfony\Component\VarDumper\Caster\MemcachedCaster', 'castMemcached'], 'WappoVendor\Ds\Collection' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DsCaster', 'castCollection'], 'WappoVendor\Ds\Map' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DsCaster', 'castMap'], 'WappoVendor\Ds\Pair' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DsCaster', 'castPair'], 'WappoVendor\Symfony\Component\VarDumper\Caster\DsPairStub' => ['WappoVendor\Symfony\Component\VarDumper\Caster\DsCaster', 'castPairStub'], 'mysqli_driver' => ['WappoVendor\Symfony\Component\VarDumper\Caster\MysqliCaster', 'castMysqliDriver'], 'CurlHandle' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'], ':curl' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'], ':dba' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'], ':dba persistent' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'], 'GdImage' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'], ':gd' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'], ':mysql link' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castMysqlLink'], ':pgsql large object' => ['WappoVendor\Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLargeObject'], ':pgsql link' => ['WappoVendor\Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'], ':pgsql link persistent' => ['WappoVendor\Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'], ':pgsql result' => ['WappoVendor\Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'], ':process' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'], ':stream' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'], 'OpenSSLCertificate' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'], ':OpenSSL X.509' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'], ':persistent stream' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'], ':stream-context' => ['WappoVendor\Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'], 'XmlParser' => ['WappoVendor\Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'], ':xml' => ['WappoVendor\Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'], 'RdKafka' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castRdKafka'], 'WappoVendor\RdKafka\Conf' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castConf'], 'WappoVendor\RdKafka\KafkaConsumer' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castKafkaConsumer'], 'WappoVendor\RdKafka\Metadata\Broker' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castBrokerMetadata'], 'WappoVendor\RdKafka\Metadata\Collection' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castCollectionMetadata'], 'WappoVendor\RdKafka\Metadata\Partition' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castPartitionMetadata'], 'WappoVendor\RdKafka\Metadata\Topic' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicMetadata'], 'WappoVendor\RdKafka\Message' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castMessage'], 'WappoVendor\RdKafka\Topic' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopic'], 'WappoVendor\RdKafka\TopicPartition' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicPartition'], 'WappoVendor\RdKafka\TopicConf' => ['WappoVendor\Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicConf']];
    protected $maxItems = 2500;
    protected $maxString = -1;
    protected $minDepth = 1;
    /**
     * @var array<string, list<callable>>
     */
    private $casters = [];
    /**
     * @var callable|null
     */
    private $prevErrorHandler;
    private $classInfo = [];
    private $filter = 0;
    /**
     * @param callable[]|null $casters A map of casters
     *
     * @see addCasters
     */
    public function __construct(array $casters = null)
    {
        if (null === $casters) {
            $casters = static::$defaultCasters;
        }
        $this->addCasters($casters);
    }
    /**
     * Adds casters for resources and objects.
     *
     * Maps resources or objects types to a callback.
     * Types are in the key, with a callable caster for value.
     * Resource types are to be prefixed with a `:`,
     * see e.g. static::$defaultCasters.
     *
     * @param callable[] $casters A map of casters
     */
    public function addCasters(array $casters)
    {
        foreach ($casters as $type => $callback) {
            $this->casters[$type][] = $callback;
        }
    }
    /**
     * Sets the maximum number of items to clone past the minimum depth in nested structures.
     */
    public function setMaxItems(int $maxItems)
    {
        $this->maxItems = $maxItems;
    }
    /**
     * Sets the maximum cloned length for strings.
     */
    public function setMaxString(int $maxString)
    {
        $this->maxString = $maxString;
    }
    /**
     * Sets the minimum tree depth where we are guaranteed to clone all the items.  After this
     * depth is reached, only setMaxItems items will be cloned.
     */
    public function setMinDepth(int $minDepth)
    {
        $this->minDepth = $minDepth;
    }
    /**
     * Clones a PHP variable.
     *
     * @param mixed $var    Any PHP variable
     * @param int   $filter A bit field of Caster::EXCLUDE_* constants
     *
     * @return Data
     */
    public function cloneVar($var, int $filter = 0)
    {
        $this->prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) {
            if (\E_RECOVERABLE_ERROR === $type || \E_USER_ERROR === $type) {
                // Cloner never dies
                throw new \ErrorException($msg, 0, $type, $file, $line);
            }
            if ($this->prevErrorHandler) {
                return ($this->prevErrorHandler)($type, $msg, $file, $line, $context);
            }
            return \false;
        });
        $this->filter = $filter;
        if ($gc = gc_enabled()) {
            gc_disable();
        }
        try {
            return new Data($this->doClone($var));
        } finally {
            if ($gc) {
                gc_enable();
            }
            restore_error_handler();
            $this->prevErrorHandler = null;
        }
    }
    /**
     * Effectively clones the PHP variable.
     *
     * @param mixed $var Any PHP variable
     *
     * @return array
     */
    abstract protected function doClone($var);
    /**
     * Casts an object to an array representation.
     *
     * @param bool $isNested True if the object is nested in the dumped structure
     *
     * @return array
     */
    protected function castObject(Stub $stub, bool $isNested)
    {
        $obj = $stub->value;
        $class = $stub->class;
        if (\PHP_VERSION_ID < 80000 ? "\x00" === ($class[15] ?? null) : str_contains($class, "@anonymous\x00")) {
            $stub->class = get_debug_type($obj);
        }
        if (isset($this->classInfo[$class])) {
            [$i, $parents, $hasDebugInfo, $fileInfo] = $this->classInfo[$class];
        } else {
            $i = 2;
            $parents = [$class];
            $hasDebugInfo = method_exists($class, '__debugInfo');
            foreach (class_parents($class) as $p) {
                $parents[] = $p;
                ++$i;
            }
            foreach (class_implements($class) as $p) {
                $parents[] = $p;
                ++$i;
            }
            $parents[] = '*';
            $r = new \ReflectionClass($class);
            $fileInfo = $r->isInternal() || $r->isSubclassOf(Stub::class) ? [] : ['file' => $r->getFileName(), 'line' => $r->getStartLine()];
            $this->classInfo[$class] = [$i, $parents, $hasDebugInfo, $fileInfo];
        }
        $stub->attr += $fileInfo;
        $a = Caster::castObject($obj, $class, $hasDebugInfo, $stub->class);
        try {
            while ($i--) {
                if (!empty($this->casters[$p = $parents[$i]])) {
                    foreach ($this->casters[$p] as $callback) {
                        $a = $callback($obj, $a, $stub, $isNested, $this->filter);
                    }
                }
            }
        } catch (\Exception $e) {
            $a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '') . '⚠' => new ThrowingCasterException($e)] + $a;
        }
        return $a;
    }
    /**
     * Casts a resource to an array representation.
     *
     * @param bool $isNested True if the object is nested in the dumped structure
     *
     * @return array
     */
    protected function castResource(Stub $stub, bool $isNested)
    {
        $a = [];
        $res = $stub->value;
        $type = $stub->class;
        try {
            if (!empty($this->casters[':' . $type])) {
                foreach ($this->casters[':' . $type] as $callback) {
                    $a = $callback($res, $a, $stub, $isNested, $this->filter);
                }
            }
        } catch (\Exception $e) {
            $a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '') . '⚠' => new ThrowingCasterException($e)] + $a;
        }
        return $a;
    }
}
