blob: 129b2cb47b989c62ea147306dfa7cbabbe1921a9 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?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
12namespace Symfony\Component\VarDumper\Caster;
13
14use Doctrine\Common\Proxy\Proxy as CommonProxy;
15use Doctrine\ORM\PersistentCollection;
16use Doctrine\ORM\Proxy\Proxy as OrmProxy;
17use Symfony\Component\VarDumper\Cloner\Stub;
18
19/**
20 * Casts Doctrine related classes to array representation.
21 *
22 * @author Nicolas Grekas <p@tchwork.com>
23 *
24 * @final
25 */
26class DoctrineCaster
27{
28 public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub, bool $isNested)
29 {
30 foreach (['__cloner__', '__initializer__'] as $k) {
31 if (\array_key_exists($k, $a)) {
32 unset($a[$k]);
33 ++$stub->cut;
34 }
35 }
36
37 return $a;
38 }
39
40 public static function castOrmProxy(OrmProxy $proxy, array $a, Stub $stub, bool $isNested)
41 {
42 foreach (['_entityPersister', '_identifier'] as $k) {
43 if (\array_key_exists($k = "\0Doctrine\\ORM\\Proxy\\Proxy\0".$k, $a)) {
44 unset($a[$k]);
45 ++$stub->cut;
46 }
47 }
48
49 return $a;
50 }
51
52 public static function castPersistentCollection(PersistentCollection $coll, array $a, Stub $stub, bool $isNested)
53 {
54 foreach (['snapshot', 'association', 'typeClass'] as $k) {
55 if (\array_key_exists($k = "\0Doctrine\\ORM\\PersistentCollection\0".$k, $a)) {
56 $a[$k] = new CutStub($a[$k]);
57 }
58 }
59
60 return $a;
61 }
62}