Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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\Cloner;
13
 
14
use Symfony\Component\VarDumper\Caster\Caster;
15
use Symfony\Component\VarDumper\Exception\ThrowingCasterException;
16
 
17
/**
18
 * AbstractCloner implements a generic caster mechanism for objects and resources.
19
 *
20
 * @author Nicolas Grekas <p@tchwork.com>
21
 */
22
abstract class AbstractCloner implements ClonerInterface
23
{
24
    public static $defaultCasters = [
25
        '__PHP_Incomplete_Class' => ['Symfony\Component\VarDumper\Caster\Caster', 'castPhpIncompleteClass'],
26
 
27
        'Symfony\Component\VarDumper\Caster\CutStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'],
28
        'Symfony\Component\VarDumper\Caster\CutArrayStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castCutArray'],
29
        'Symfony\Component\VarDumper\Caster\ConstStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'],
30
        'Symfony\Component\VarDumper\Caster\EnumStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castEnum'],
31
 
32
        'Fiber' => ['Symfony\Component\VarDumper\Caster\FiberCaster', 'castFiber'],
33
 
34
        'Closure' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClosure'],
35
        'Generator' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castGenerator'],
36
        'ReflectionType' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castType'],
37
        'ReflectionAttribute' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castAttribute'],
38
        'ReflectionGenerator' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castReflectionGenerator'],
39
        'ReflectionClass' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClass'],
40
        'ReflectionClassConstant' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClassConstant'],
41
        'ReflectionFunctionAbstract' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castFunctionAbstract'],
42
        'ReflectionMethod' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castMethod'],
43
        'ReflectionParameter' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castParameter'],
44
        'ReflectionProperty' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castProperty'],
45
        'ReflectionReference' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castReference'],
46
        'ReflectionExtension' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castExtension'],
47
        'ReflectionZendExtension' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castZendExtension'],
48
 
49
        'Doctrine\Common\Persistence\ObjectManager' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
50
        'Doctrine\Common\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castCommonProxy'],
51
        'Doctrine\ORM\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castOrmProxy'],
52
        'Doctrine\ORM\PersistentCollection' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castPersistentCollection'],
53
        'Doctrine\Persistence\ObjectManager' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
54
 
55
        'DOMException' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castException'],
56
        'DOMStringList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
57
        'DOMNameList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
58
        'DOMImplementation' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castImplementation'],
59
        'DOMImplementationList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
60
        'DOMNode' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNode'],
61
        'DOMNameSpaceNode' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNameSpaceNode'],
62
        'DOMDocument' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocument'],
63
        'DOMNodeList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
64
        'DOMNamedNodeMap' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],
65
        'DOMCharacterData' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castCharacterData'],
66
        'DOMAttr' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castAttr'],
67
        'DOMElement' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castElement'],
68
        'DOMText' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castText'],
69
        'DOMDocumentType' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocumentType'],
70
        'DOMNotation' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNotation'],
71
        'DOMEntity' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castEntity'],
72
        'DOMProcessingInstruction' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castProcessingInstruction'],
73
        'DOMXPath' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castXPath'],
74
 
75
        'XMLReader' => ['Symfony\Component\VarDumper\Caster\XmlReaderCaster', 'castXmlReader'],
76
 
77
        'ErrorException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castErrorException'],
78
        'Exception' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castException'],
79
        'Error' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castError'],
80
        'Symfony\Bridge\Monolog\Logger' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
81
        'Symfony\Component\DependencyInjection\ContainerInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
82
        'Symfony\Component\EventDispatcher\EventDispatcherInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
83
        'Symfony\Component\HttpClient\AmpHttpClient' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'],
84
        'Symfony\Component\HttpClient\CurlHttpClient' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'],
85
        'Symfony\Component\HttpClient\NativeHttpClient' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'],
86
        'Symfony\Component\HttpClient\Response\AmpResponse' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'],
87
        'Symfony\Component\HttpClient\Response\CurlResponse' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'],
88
        'Symfony\Component\HttpClient\Response\NativeResponse' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'],
89
        'Symfony\Component\HttpFoundation\Request' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'],
90
        'Symfony\Component\Uid\Ulid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUlid'],
91
        'Symfony\Component\Uid\Uuid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUuid'],
92
        'Symfony\Component\VarExporter\Internal\LazyObjectState' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castLazyObjectState'],
93
        'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'],
94
        'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'],
95
        'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'],
96
        'Symfony\Component\VarDumper\Cloner\AbstractCloner' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
97
        'Symfony\Component\ErrorHandler\Exception\SilencedErrorContext' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'],
98
 
99
        'Imagine\Image\ImageInterface' => ['Symfony\Component\VarDumper\Caster\ImagineCaster', 'castImage'],
100
 
101
        'Ramsey\Uuid\UuidInterface' => ['Symfony\Component\VarDumper\Caster\UuidCaster', 'castRamseyUuid'],
102
 
103
        'ProxyManager\Proxy\ProxyInterface' => ['Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'],
104
        'PHPUnit_Framework_MockObject_MockObject' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
105
        'PHPUnit\Framework\MockObject\MockObject' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
106
        'PHPUnit\Framework\MockObject\Stub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
107
        'Prophecy\Prophecy\ProphecySubjectInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
108
        'Mockery\MockInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
109
 
110
        'PDO' => ['Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdo'],
111
        'PDOStatement' => ['Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdoStatement'],
112
 
113
        'AMQPConnection' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castConnection'],
114
        'AMQPChannel' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castChannel'],
115
        'AMQPQueue' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castQueue'],
116
        'AMQPExchange' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castExchange'],
117
        'AMQPEnvelope' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castEnvelope'],
118
 
119
        'ArrayObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayObject'],
120
        'ArrayIterator' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayIterator'],
121
        'SplDoublyLinkedList' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'],
122
        'SplFileInfo' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'],
123
        'SplFileObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'],
124
        'SplHeap' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'],
125
        'SplObjectStorage' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castObjectStorage'],
126
        'SplPriorityQueue' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'],
127
        'OuterIterator' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castOuterIterator'],
128
        'WeakReference' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castWeakReference'],
129
 
130
        'Redis' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedis'],
131
        'RedisArray' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisArray'],
132
        'RedisCluster' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisCluster'],
133
 
134
        'DateTimeInterface' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castDateTime'],
135
        'DateInterval' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castInterval'],
136
        'DateTimeZone' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'],
137
        'DatePeriod' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castPeriod'],
138
 
139
        'GMP' => ['Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'],
140
 
141
        'MessageFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'],
142
        'NumberFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castNumberFormatter'],
143
        'IntlTimeZone' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlTimeZone'],
144
        'IntlCalendar' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlCalendar'],
145
        'IntlDateFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlDateFormatter'],
146
 
147
        'Memcached' => ['Symfony\Component\VarDumper\Caster\MemcachedCaster', 'castMemcached'],
148
 
149
        'Ds\Collection' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castCollection'],
150
        'Ds\Map' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castMap'],
151
        'Ds\Pair' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castPair'],
152
        'Symfony\Component\VarDumper\Caster\DsPairStub' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castPairStub'],
153
 
154
        'mysqli_driver' => ['Symfony\Component\VarDumper\Caster\MysqliCaster', 'castMysqliDriver'],
155
 
156
        'CurlHandle' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
157
 
158
        ':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
159
        ':dba persistent' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
160
 
161
        'GdImage' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'],
162
        ':gd' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'],
163
 
164
        ':pgsql large object' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLargeObject'],
165
        ':pgsql link' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'],
166
        ':pgsql link persistent' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'],
167
        ':pgsql result' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'],
168
        ':process' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'],
169
        ':stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'],
170
 
171
        'OpenSSLCertificate' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'],
172
        ':OpenSSL X.509' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'],
173
 
174
        ':persistent stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'],
175
        ':stream-context' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'],
176
 
177
        'XmlParser' => ['Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'],
178
        ':xml' => ['Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'],
179
 
180
        'RdKafka' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castRdKafka'],
181
        'RdKafka\Conf' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castConf'],
182
        'RdKafka\KafkaConsumer' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castKafkaConsumer'],
183
        'RdKafka\Metadata\Broker' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castBrokerMetadata'],
184
        'RdKafka\Metadata\Collection' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castCollectionMetadata'],
185
        'RdKafka\Metadata\Partition' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castPartitionMetadata'],
186
        'RdKafka\Metadata\Topic' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicMetadata'],
187
        'RdKafka\Message' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castMessage'],
188
        'RdKafka\Topic' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopic'],
189
        'RdKafka\TopicPartition' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicPartition'],
190
        'RdKafka\TopicConf' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicConf'],
191
 
192
        'FFI\CData' => ['Symfony\Component\VarDumper\Caster\FFICaster', 'castCTypeOrCData'],
193
        'FFI\CType' => ['Symfony\Component\VarDumper\Caster\FFICaster', 'castCTypeOrCData'],
194
    ];
195
 
196
    protected $maxItems = 2500;
197
    protected $maxString = -1;
198
    protected $minDepth = 1;
199
 
200
    /**
201
     * @var array<string, list<callable>>
202
     */
203
    private array $casters = [];
204
 
205
    /**
206
     * @var callable|null
207
     */
208
    private $prevErrorHandler;
209
 
210
    private array $classInfo = [];
211
    private int $filter = 0;
212
 
213
    /**
214
     * @param callable[]|null $casters A map of casters
215
     *
216
     * @see addCasters
217
     */
218
    public function __construct(array $casters = null)
219
    {
220
        $this->addCasters($casters ?? static::$defaultCasters);
221
    }
222
 
223
    /**
224
     * Adds casters for resources and objects.
225
     *
226
     * Maps resources or objects types to a callback.
227
     * Types are in the key, with a callable caster for value.
228
     * Resource types are to be prefixed with a `:`,
229
     * see e.g. static::$defaultCasters.
230
     *
231
     * @param callable[] $casters A map of casters
232
     */
233
    public function addCasters(array $casters)
234
    {
235
        foreach ($casters as $type => $callback) {
236
            $this->casters[$type][] = $callback;
237
        }
238
    }
239
 
240
    /**
241
     * Sets the maximum number of items to clone past the minimum depth in nested structures.
242
     */
243
    public function setMaxItems(int $maxItems)
244
    {
245
        $this->maxItems = $maxItems;
246
    }
247
 
248
    /**
249
     * Sets the maximum cloned length for strings.
250
     */
251
    public function setMaxString(int $maxString)
252
    {
253
        $this->maxString = $maxString;
254
    }
255
 
256
    /**
257
     * Sets the minimum tree depth where we are guaranteed to clone all the items.  After this
258
     * depth is reached, only setMaxItems items will be cloned.
259
     */
260
    public function setMinDepth(int $minDepth)
261
    {
262
        $this->minDepth = $minDepth;
263
    }
264
 
265
    /**
266
     * Clones a PHP variable.
267
     *
268
     * @param int $filter A bit field of Caster::EXCLUDE_* constants
269
     */
270
    public function cloneVar(mixed $var, int $filter = 0): Data
271
    {
272
        $this->prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) {
273
            if (\E_RECOVERABLE_ERROR === $type || \E_USER_ERROR === $type) {
274
                // Cloner never dies
275
                throw new \ErrorException($msg, 0, $type, $file, $line);
276
            }
277
 
278
            if ($this->prevErrorHandler) {
279
                return ($this->prevErrorHandler)($type, $msg, $file, $line, $context);
280
            }
281
 
282
            return false;
283
        });
284
        $this->filter = $filter;
285
 
286
        if ($gc = gc_enabled()) {
287
            gc_disable();
288
        }
289
        try {
290
            return new Data($this->doClone($var));
291
        } finally {
292
            if ($gc) {
293
                gc_enable();
294
            }
295
            restore_error_handler();
296
            $this->prevErrorHandler = null;
297
        }
298
    }
299
 
300
    /**
301
     * Effectively clones the PHP variable.
302
     */
303
    abstract protected function doClone(mixed $var): array;
304
 
305
    /**
306
     * Casts an object to an array representation.
307
     *
308
     * @param bool $isNested True if the object is nested in the dumped structure
309
     */
310
    protected function castObject(Stub $stub, bool $isNested): array
311
    {
312
        $obj = $stub->value;
313
        $class = $stub->class;
314
 
315
        if (str_contains($class, "@anonymous\0")) {
316
            $stub->class = get_debug_type($obj);
317
        }
318
        if (isset($this->classInfo[$class])) {
319
            [$i, $parents, $hasDebugInfo, $fileInfo] = $this->classInfo[$class];
320
        } else {
321
            $i = 2;
322
            $parents = [$class];
323
            $hasDebugInfo = method_exists($class, '__debugInfo');
324
 
325
            foreach (class_parents($class) as $p) {
326
                $parents[] = $p;
327
                ++$i;
328
            }
329
            foreach (class_implements($class) as $p) {
330
                $parents[] = $p;
331
                ++$i;
332
            }
333
            $parents[] = '*';
334
 
335
            $r = new \ReflectionClass($class);
336
            $fileInfo = $r->isInternal() || $r->isSubclassOf(Stub::class) ? [] : [
337
                'file' => $r->getFileName(),
338
                'line' => $r->getStartLine(),
339
            ];
340
 
341
            $this->classInfo[$class] = [$i, $parents, $hasDebugInfo, $fileInfo];
342
        }
343
 
344
        $stub->attr += $fileInfo;
345
        $a = Caster::castObject($obj, $class, $hasDebugInfo, $stub->class);
346
 
347
        try {
348
            while ($i--) {
349
                if (!empty($this->casters[$p = $parents[$i]])) {
350
                    foreach ($this->casters[$p] as $callback) {
351
                        $a = $callback($obj, $a, $stub, $isNested, $this->filter);
352
                    }
353
                }
354
            }
355
        } catch (\Exception $e) {
356
            $a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)] + $a;
357
        }
358
 
359
        return $a;
360
    }
361
 
362
    /**
363
     * Casts a resource to an array representation.
364
     *
365
     * @param bool $isNested True if the object is nested in the dumped structure
366
     */
367
    protected function castResource(Stub $stub, bool $isNested): array
368
    {
369
        $a = [];
370
        $res = $stub->value;
371
        $type = $stub->class;
372
 
373
        try {
374
            if (!empty($this->casters[':'.$type])) {
375
                foreach ($this->casters[':'.$type] as $callback) {
376
                    $a = $callback($res, $a, $stub, $isNested, $this->filter);
377
                }
378
            }
379
        } catch (\Exception $e) {
380
            $a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)] + $a;
381
        }
382
 
383
        return $a;
384
    }
385
}