Sin descripción

DoctrineCaster.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. * @final since Symfony 4.4
  21. */
  22. class DoctrineCaster
  23. {
  24. public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub, $isNested)
  25. {
  26. foreach (['__cloner__', '__initializer__'] as $k) {
  27. if (\array_key_exists($k, $a)) {
  28. unset($a[$k]);
  29. ++$stub->cut;
  30. }
  31. }
  32. return $a;
  33. }
  34. public static function castOrmProxy(OrmProxy $proxy, array $a, Stub $stub, $isNested)
  35. {
  36. foreach (['_entityPersister', '_identifier'] as $k) {
  37. if (\array_key_exists($k = "\0Doctrine\\ORM\\Proxy\\Proxy\0".$k, $a)) {
  38. unset($a[$k]);
  39. ++$stub->cut;
  40. }
  41. }
  42. return $a;
  43. }
  44. public static function castPersistentCollection(PersistentCollection $coll, array $a, Stub $stub, $isNested)
  45. {
  46. foreach (['snapshot', 'association', 'typeClass'] as $k) {
  47. if (\array_key_exists($k = "\0Doctrine\\ORM\\PersistentCollection\0".$k, $a)) {
  48. $a[$k] = new CutStub($a[$k]);
  49. }
  50. }
  51. return $a;
  52. }
  53. }