You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

3 years ago
  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. class DoctrineCaster
  23. {
  24. public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub, bool $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, bool $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, bool $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. }