"Fossies" - the Fresh Open Source Software Archive 
Member "drupal-9.4.5/vendor/symfony/var-dumper/Cloner/AbstractCloner.php" (20 Jul 2022, 21170 Bytes) of package /linux/www/drupal-9.4.5.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "AbstractCloner.php":
9.3.16_vs_9.4.0.
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 'DOMTypeinfo' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castTypeinfo'],
70 'DOMDomError' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDomError'],
71 'DOMLocator' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLocator'],
72 'DOMDocumentType' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castDocumentType'],
73 'DOMNotation' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castNotation'],
74 'DOMEntity' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castEntity'],
75 'DOMProcessingInstruction' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castProcessingInstruction'],
76 'DOMXPath' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castXPath'],
77
78 'XMLReader' => ['Symfony\Component\VarDumper\Caster\XmlReaderCaster', 'castXmlReader'],
79
80 'ErrorException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castErrorException'],
81 'Exception' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castException'],
82 'Error' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castError'],
83 'Symfony\Bridge\Monolog\Logger' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
84 'Symfony\Component\DependencyInjection\ContainerInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
85 'Symfony\Component\EventDispatcher\EventDispatcherInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
86 'Symfony\Component\HttpClient\AmpHttpClient' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'],
87 'Symfony\Component\HttpClient\CurlHttpClient' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'],
88 'Symfony\Component\HttpClient\NativeHttpClient' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'],
89 'Symfony\Component\HttpClient\Response\AmpResponse' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'],
90 'Symfony\Component\HttpClient\Response\CurlResponse' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'],
91 'Symfony\Component\HttpClient\Response\NativeResponse' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'],
92 'Symfony\Component\HttpFoundation\Request' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'],
93 'Symfony\Component\Uid\Ulid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUlid'],
94 'Symfony\Component\Uid\Uuid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUuid'],
95 'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'],
96 'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'],
97 'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'],
98 'Symfony\Component\VarDumper\Cloner\AbstractCloner' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
99 'Symfony\Component\ErrorHandler\Exception\SilencedErrorContext' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castSilencedErrorContext'],
100
101 'Imagine\Image\ImageInterface' => ['Symfony\Component\VarDumper\Caster\ImagineCaster', 'castImage'],
102
103 'Ramsey\Uuid\UuidInterface' => ['Symfony\Component\VarDumper\Caster\UuidCaster', 'castRamseyUuid'],
104
105 'ProxyManager\Proxy\ProxyInterface' => ['Symfony\Component\VarDumper\Caster\ProxyManagerCaster', 'castProxy'],
106 'PHPUnit_Framework_MockObject_MockObject' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
107 'PHPUnit\Framework\MockObject\MockObject' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
108 'PHPUnit\Framework\MockObject\Stub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
109 'Prophecy\Prophecy\ProphecySubjectInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
110 'Mockery\MockInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
111
112 'PDO' => ['Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdo'],
113 'PDOStatement' => ['Symfony\Component\VarDumper\Caster\PdoCaster', 'castPdoStatement'],
114
115 'AMQPConnection' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castConnection'],
116 'AMQPChannel' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castChannel'],
117 'AMQPQueue' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castQueue'],
118 'AMQPExchange' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castExchange'],
119 'AMQPEnvelope' => ['Symfony\Component\VarDumper\Caster\AmqpCaster', 'castEnvelope'],
120
121 'ArrayObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayObject'],
122 'ArrayIterator' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayIterator'],
123 'SplDoublyLinkedList' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'],
124 'SplFileInfo' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'],
125 'SplFileObject' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'],
126 'SplHeap' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'],
127 'SplObjectStorage' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castObjectStorage'],
128 'SplPriorityQueue' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castHeap'],
129 'OuterIterator' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castOuterIterator'],
130 'WeakReference' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castWeakReference'],
131
132 'Redis' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedis'],
133 'RedisArray' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisArray'],
134 'RedisCluster' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisCluster'],
135
136 'DateTimeInterface' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castDateTime'],
137 'DateInterval' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castInterval'],
138 'DateTimeZone' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'],
139 'DatePeriod' => ['Symfony\Component\VarDumper\Caster\DateCaster', 'castPeriod'],
140
141 'GMP' => ['Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'],
142
143 'MessageFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'],
144 'NumberFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castNumberFormatter'],
145 'IntlTimeZone' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlTimeZone'],
146 'IntlCalendar' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlCalendar'],
147 'IntlDateFormatter' => ['Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlDateFormatter'],
148
149 'Memcached' => ['Symfony\Component\VarDumper\Caster\MemcachedCaster', 'castMemcached'],
150
151 'Ds\Collection' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castCollection'],
152 'Ds\Map' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castMap'],
153 'Ds\Pair' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castPair'],
154 'Symfony\Component\VarDumper\Caster\DsPairStub' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castPairStub'],
155
156 'mysqli_driver' => ['Symfony\Component\VarDumper\Caster\MysqliCaster', 'castMysqliDriver'],
157
158 'CurlHandle' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
159 ':curl' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
160
161 ':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
162 ':dba persistent' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
163
164 'GdImage' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'],
165 ':gd' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'],
166
167 ':mysql link' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castMysqlLink'],
168 ':pgsql large object' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLargeObject'],
169 ':pgsql link' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'],
170 ':pgsql link persistent' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castLink'],
171 ':pgsql result' => ['Symfony\Component\VarDumper\Caster\PgSqlCaster', 'castResult'],
172 ':process' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castProcess'],
173 ':stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'],
174
175 'OpenSSLCertificate' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'],
176 ':OpenSSL X.509' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castOpensslX509'],
177
178 ':persistent stream' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'],
179 ':stream-context' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'],
180
181 'XmlParser' => ['Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'],
182 ':xml' => ['Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'],
183
184 'RdKafka' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castRdKafka'],
185 'RdKafka\Conf' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castConf'],
186 'RdKafka\KafkaConsumer' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castKafkaConsumer'],
187 'RdKafka\Metadata\Broker' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castBrokerMetadata'],
188 'RdKafka\Metadata\Collection' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castCollectionMetadata'],
189 'RdKafka\Metadata\Partition' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castPartitionMetadata'],
190 'RdKafka\Metadata\Topic' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicMetadata'],
191 'RdKafka\Message' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castMessage'],
192 'RdKafka\Topic' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopic'],
193 'RdKafka\TopicPartition' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicPartition'],
194 'RdKafka\TopicConf' => ['Symfony\Component\VarDumper\Caster\RdKafkaCaster', 'castTopicConf'],
195 ];
196
197 protected $maxItems = 2500;
198 protected $maxString = -1;
199 protected $minDepth = 1;
200
201 /**
202 * @var array<string, list<callable>>
203 */
204 private $casters = [];
205
206 /**
207 * @var callable|null
208 */
209 private $prevErrorHandler;
210
211 private $classInfo = [];
212 private $filter = 0;
213
214 /**
215 * @param callable[]|null $casters A map of casters
216 *
217 * @see addCasters
218 */
219 public function __construct(array $casters = null)
220 {
221 if (null === $casters) {
222 $casters = static::$defaultCasters;
223 }
224 $this->addCasters($casters);
225 }
226
227 /**
228 * Adds casters for resources and objects.
229 *
230 * Maps resources or objects types to a callback.
231 * Types are in the key, with a callable caster for value.
232 * Resource types are to be prefixed with a `:`,
233 * see e.g. static::$defaultCasters.
234 *
235 * @param callable[] $casters A map of casters
236 */
237 public function addCasters(array $casters)
238 {
239 foreach ($casters as $type => $callback) {
240 $this->casters[$type][] = $callback;
241 }
242 }
243
244 /**
245 * Sets the maximum number of items to clone past the minimum depth in nested structures.
246 */
247 public function setMaxItems(int $maxItems)
248 {
249 $this->maxItems = $maxItems;
250 }
251
252 /**
253 * Sets the maximum cloned length for strings.
254 */
255 public function setMaxString(int $maxString)
256 {
257 $this->maxString = $maxString;
258 }
259
260 /**
261 * Sets the minimum tree depth where we are guaranteed to clone all the items. After this
262 * depth is reached, only setMaxItems items will be cloned.
263 */
264 public function setMinDepth(int $minDepth)
265 {
266 $this->minDepth = $minDepth;
267 }
268
269 /**
270 * Clones a PHP variable.
271 *
272 * @param mixed $var Any PHP variable
273 * @param int $filter A bit field of Caster::EXCLUDE_* constants
274 *
275 * @return Data
276 */
277 public function cloneVar($var, int $filter = 0)
278 {
279 $this->prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) {
280 if (\E_RECOVERABLE_ERROR === $type || \E_USER_ERROR === $type) {
281 // Cloner never dies
282 throw new \ErrorException($msg, 0, $type, $file, $line);
283 }
284
285 if ($this->prevErrorHandler) {
286 return ($this->prevErrorHandler)($type, $msg, $file, $line, $context);
287 }
288
289 return false;
290 });
291 $this->filter = $filter;
292
293 if ($gc = gc_enabled()) {
294 gc_disable();
295 }
296 try {
297 return new Data($this->doClone($var));
298 } finally {
299 if ($gc) {
300 gc_enable();
301 }
302 restore_error_handler();
303 $this->prevErrorHandler = null;
304 }
305 }
306
307 /**
308 * Effectively clones the PHP variable.
309 *
310 * @param mixed $var Any PHP variable
311 *
312 * @return array
313 */
314 abstract protected function doClone($var);
315
316 /**
317 * Casts an object to an array representation.
318 *
319 * @param bool $isNested True if the object is nested in the dumped structure
320 *
321 * @return array
322 */
323 protected function castObject(Stub $stub, bool $isNested)
324 {
325 $obj = $stub->value;
326 $class = $stub->class;
327
328 if (\PHP_VERSION_ID < 80000 ? "\0" === ($class[15] ?? null) : str_contains($class, "@anonymous\0")) {
329 $stub->class = get_debug_type($obj);
330 }
331 if (isset($this->classInfo[$class])) {
332 [$i, $parents, $hasDebugInfo, $fileInfo] = $this->classInfo[$class];
333 } else {
334 $i = 2;
335 $parents = [$class];
336 $hasDebugInfo = method_exists($class, '__debugInfo');
337
338 foreach (class_parents($class) as $p) {
339 $parents[] = $p;
340 ++$i;
341 }
342 foreach (class_implements($class) as $p) {
343 $parents[] = $p;
344 ++$i;
345 }
346 $parents[] = '*';
347
348 $r = new \ReflectionClass($class);
349 $fileInfo = $r->isInternal() || $r->isSubclassOf(Stub::class) ? [] : [
350 'file' => $r->getFileName(),
351 'line' => $r->getStartLine(),
352 ];
353
354 $this->classInfo[$class] = [$i, $parents, $hasDebugInfo, $fileInfo];
355 }
356
357 $stub->attr += $fileInfo;
358 $a = Caster::castObject($obj, $class, $hasDebugInfo, $stub->class);
359
360 try {
361 while ($i--) {
362 if (!empty($this->casters[$p = $parents[$i]])) {
363 foreach ($this->casters[$p] as $callback) {
364 $a = $callback($obj, $a, $stub, $isNested, $this->filter);
365 }
366 }
367 }
368 } catch (\Exception $e) {
369 $a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)] + $a;
370 }
371
372 return $a;
373 }
374
375 /**
376 * Casts a resource to an array representation.
377 *
378 * @param bool $isNested True if the object is nested in the dumped structure
379 *
380 * @return array
381 */
382 protected function castResource(Stub $stub, bool $isNested)
383 {
384 $a = [];
385 $res = $stub->value;
386 $type = $stub->class;
387
388 try {
389 if (!empty($this->casters[':'.$type])) {
390 foreach ($this->casters[':'.$type] as $callback) {
391 $a = $callback($res, $a, $stub, $isNested, $this->filter);
392 }
393 }
394 } catch (\Exception $e) {
395 $a = [(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)] + $a;
396 }
397
398 return $a;
399 }
400 }