Caster.php

  1. 8.0.x lib/Drush/Psysh/Caster.php
  2. master lib/Drush/Psysh/Caster.php

Contains \Drush\Psysh\Caster.

Namespace

Drush\Psysh

Classes

Namesort descending Description
Caster Caster class for VarDumper casters for the shell.

File

lib/Drush/Psysh/Caster.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drush\Psysh\Caster.
  5. */
  6. namespace Drush\Psysh;
  7. use Symfony\Component\VarDumper\Caster\Caster as BaseCaster;
  8. /**
  9. * Caster class for VarDumper casters for the shell.
  10. */
  11. class Caster {
  12. /**
  13. * Casts \Drupal\Core\Entity\ContentEntityInterface classes.
  14. */
  15. public static function castContentEntity($entity, $array, $stub, $isNested) {
  16. if (!$isNested) {
  17. foreach ($entity as $property => $item) {
  18. $array[BaseCaster::PREFIX_PROTECTED . $property] = $item;
  19. }
  20. }
  21. return $array;
  22. }
  23. /**
  24. * Casts \Drupal\Core\Field\FieldItemListInterface classes.
  25. */
  26. public static function castFieldItemList($list_item, $array, $stub, $isNested) {
  27. if (!$isNested) {
  28. foreach ($list_item as $delta => $item) {
  29. $array[BaseCaster::PREFIX_VIRTUAL . $delta] = $item;
  30. }
  31. }
  32. return $array;
  33. }
  34. /**
  35. * Casts \Drupal\Core\Field\FieldItemInterface classes.
  36. */
  37. public static function castFieldItem($item, $array, $stub, $isNested) {
  38. if (!$isNested) {
  39. $array[BaseCaster::PREFIX_VIRTUAL . 'value'] = $item->getValue();
  40. }
  41. return $array;
  42. }
  43. /**
  44. * Casts \Drupal\Core\Config\Entity\ConfigEntityInterface classes.
  45. */
  46. public static function castConfigEntity($entity, $array, $stub, $isNested) {
  47. if (!$isNested) {
  48. foreach ($entity->toArray() as $property => $value) {
  49. $array[BaseCaster::PREFIX_PROTECTED . $property] = $value;
  50. }
  51. }
  52. return $array;
  53. }
  54. /**
  55. * Casts \Drupal\Core\Config\ConfigBase classes.
  56. */
  57. public static function castConfig($config, $array, $stub, $isNested) {
  58. if (!$isNested) {
  59. foreach ($config->get() as $property => $value) {
  60. $array[BaseCaster::PREFIX_VIRTUAL . $property] = $value;
  61. }
  62. }
  63. return $array;
  64. }
  65. }