StubCaster.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 Symfony\Component\VarDumper\Cloner\Stub;
  12. /**
  13. * Casts a caster's Stub.
  14. *
  15. * @author Nicolas Grekas <p@tchwork.com>
  16. */
  17. class StubCaster
  18. {
  19. public static function castStub(Stub $c, array $a, Stub $stub, $isNested)
  20. {
  21. if ($isNested) {
  22. $stub->type = $c->type;
  23. $stub->class = $c->class;
  24. $stub->value = $c->value;
  25. $stub->handle = $c->handle;
  26. $stub->cut = $c->cut;
  27. $a = array();
  28. }
  29. return $a;
  30. }
  31. public static function castCutArray(CutArrayStub $c, array $a, Stub $stub, $isNested)
  32. {
  33. return $isNested ? $c->preservedSubset : $a;
  34. }
  35. public static function cutInternals($obj, array $a, Stub $stub, $isNested)
  36. {
  37. if ($isNested) {
  38. $stub->cut += count($a);
  39. return array();
  40. }
  41. return $a;
  42. }
  43. public static function castEnum(EnumStub $c, array $a, Stub $stub, $isNested)
  44. {
  45. if ($isNested) {
  46. $stub->class = '';
  47. $stub->handle = 0;
  48. $stub->value = null;
  49. $a = array();
  50. if ($c->value) {
  51. foreach (array_keys($c->value) as $k) {
  52. $keys[] = !isset($k[0]) || "\0" !== $k[0] ? Caster::PREFIX_VIRTUAL.$k : $k;
  53. }
  54. // Preserve references with array_combine()
  55. $a = array_combine($keys, $c->value);
  56. }
  57. }
  58. return $a;
  59. }
  60. }