Drupal investigation

StubCaster.php 1.7KB

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