DoctrineCaster.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 (array('__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 (array('_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 (array('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. }