DoctrineCaster.php 1.6 KB

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