DoctrineCaster.php 1.7 KB

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