Keine Beschreibung

StubCaster.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. $stub->attr = $c->attr;
  28. if (Stub::TYPE_REF === $c->type && !$c->class && is_string($c->value) && !preg_match('//u', $c->value)) {
  29. $stub->type = Stub::TYPE_STRING;
  30. $stub->class = Stub::STRING_BINARY;
  31. }
  32. return array();
  33. }
  34. }
  35. public static function castCutArray(CutArrayStub $c, array $a, Stub $stub, $isNested)
  36. {
  37. return $isNested ? $c->preservedSubset : $a;
  38. }
  39. public static function cutInternals($obj, array $a, Stub $stub, $isNested)
  40. {
  41. if ($isNested) {
  42. $stub->cut += count($a);
  43. return array();
  44. }
  45. return $a;
  46. }
  47. public static function castEnum(EnumStub $c, array $a, Stub $stub, $isNested)
  48. {
  49. if ($isNested) {
  50. $stub->class = $c->dumpKeys ? '' : null;
  51. $stub->handle = 0;
  52. $stub->value = null;
  53. $stub->cut = $c->cut;
  54. $stub->attr = $c->attr;
  55. $a = array();
  56. if ($c->value) {
  57. foreach (array_keys($c->value) as $k) {
  58. $keys[] = !isset($k[0]) || "\0" !== $k[0] ? Caster::PREFIX_VIRTUAL.$k : $k;
  59. }
  60. // Preserve references with array_combine()
  61. $a = array_combine($keys, $c->value);
  62. }
  63. }
  64. return $a;
  65. }
  66. }