AbstractCloner.php 20 KB

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