8000 [VarDumper] casters for Doctrine objects · symfony/symfony@c426d8b · GitHub
[go: up one dir, main page]

Skip to content

Commit c426d8b

Browse files
[VarDumper] casters for Doctrine objects
1 parent 0a92c08 commit c426d8b

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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\Caster;
13+
14+
use Doctrine\Common\Persistence\ObjectManager;
15+
use Doctrine\Common\Proxy\Proxy as CommonProxy;
16+
use Doctrine\ORM\Proxy\Proxy as OrmProxy;
17+
use Doctrine\ORM\PersistentCollection;
18+
19+
/**
20+
* Casts Doctrine related classes to array representation.
21+
*
22+
* @author Nicolas Grekas <p@tchwork.com>
23+
*/
24+
class DoctrineCaster
25+
{
26+
public static function castCommonProxy(CommonProxy $proxy, array $a, $isNested, &$cut)
27+
{
28+
unset(
29+
$a['__cloner__'],
30+
$a['__initializer__']
31+
);
32+
$cut += 2;
33+
34+
return $a;
35+
}
36+
37+
public static function castOrmProxy(OrmProxy $proxy, array $a, $isNested, &$cut)
38+
{
39+
$prefix = "\0Doctrine\\ORM\\Proxy\\Proxy\0";
40+
unset(
41+
$a[$prefix.'_entityPersister'],
42+
$a[$prefix.'_identifier']
43+
);
44+
$cut += 2;
45+
46+
return $a;
47+
}
48+
49+
public static function castObjectManager(ObjectManager $manager, array $a, $isNested, &$cut)
50+
{
51+
if ($isNested) {
52+
$cut += count($a);
53+
54+
return array();
55+
}
56+
57+
return $a;
58+
}
59+
60+
public static function castPersistentCollection(PersistentCollection $coll, array $a, $isNested, &$cut)
61+
{
62+
$prefix = "\0Doctrine\\ORM\\PersistentCollection\0";
63+
unset(
64+
$a[$prefix.'snapshot'],
65+
$a[$prefix.'association'],
66+
$a[$prefix.'em'],
67+
$a[$prefix.'typeClass']
68+
);
69+
$cut += 4;
70+
71+
return $a;
72+
}
73+
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ abstract class AbstractCloner implements ClonerInterface
2424
'o:Closure' => 'Symfony\Component\VarDumper\Caster\ReflectionCaster::castClosure',
2525
'o:Reflector' => 'Symfony\Component\VarDumper\Caster\ReflectionCaster::castReflector',
2626

27+
'o:Doctrine\Common\Persistence\ObjectManager' => 'Symfony\Component\VarDumper\Caster\DoctrineCaster::castObjectManager',
28+
'o:Doctrine\Common\Proxy\Proxy' => 'Symfony\Component\VarDumper\Caster\DoctrineCaster::castCommonProxy',
29+
'o:Doctrine\ORM\Proxy\Proxy' => 'Symfony\Component\VarDumper\Caster\DoctrineCaster::castOrmProxy',
30+
'o:Doctrine\ORM\PersistentCollection' => 'Symfony\Component\VarDumper\Caster\DoctrineCaster::castPersistentCollection',
31+
2732
'o:ErrorException' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castErrorException',
2833
'o:Exception' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castException',
2934
'o:Symfony\Component\VarDumper\Exception\ThrowingCasterException'

0 commit comments

Comments
 (0)
0