adfa901b538da53a5b651d0e087865f4af0e3d1a
[yaffs-website] / vendor / drush / drush / lib / Drush / Psysh / Caster.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drush\Psysh\Caster.
6  */
7
8 namespace Drush\Psysh;
9
10 use Symfony\Component\VarDumper\Caster\Caster as BaseCaster;
11
12 /**
13  * Caster class for VarDumper casters for the shell.
14  */
15 class Caster {
16
17   /**
18    * Casts \Drupal\Core\Entity\ContentEntityInterface classes.
19    */
20   public static function castContentEntity($entity, $array, $stub, $isNested) {
21     if (!$isNested) {
22       foreach ($entity as $property => $item) {
23         $array[BaseCaster::PREFIX_PROTECTED . $property] = $item;
24       }
25     }
26
27     return $array;
28   }
29
30   /**
31    * Casts \Drupal\Core\Field\FieldItemListInterface classes.
32    */
33   public static function castFieldItemList($list_item, $array, $stub, $isNested) {
34     if (!$isNested) {
35       foreach ($list_item as $delta => $item) {
36         $array[BaseCaster::PREFIX_VIRTUAL . $delta] = $item;
37       }
38     }
39
40     return $array;
41   }
42
43   /**
44    * Casts \Drupal\Core\Field\FieldItemInterface classes.
45    */
46   public static function castFieldItem($item, $array, $stub, $isNested) {
47     if (!$isNested) {
48       $array[BaseCaster::PREFIX_VIRTUAL . 'value'] = $item->getValue();
49     }
50
51     return $array;
52   }
53
54   /**
55    * Casts \Drupal\Core\Config\Entity\ConfigEntityInterface classes.
56    */
57   public static function castConfigEntity($entity, $array, $stub, $isNested) {
58     if (!$isNested) {
59       foreach ($entity->toArray() as $property => $value) {
60         $array[BaseCaster::PREFIX_PROTECTED . $property] = $value;
61       }
62     }
63
64     return $array;
65   }
66
67   /**
68    * Casts \Drupal\Core\Config\ConfigBase classes.
69    */
70   public static function castConfig($config, $array, $stub, $isNested) {
71     if (!$isNested) {
72       foreach ($config->get() as $property => $value) {
73         $array[BaseCaster::PREFIX_VIRTUAL . $property] = $value;
74       }
75     }
76
77     return $array;
78   }
79
80   /**
81    * Casts \Drupal\Component\DependencyInjection\Container classes.
82    */
83   public static function castContainer($container, $array, $stub, $isNested) {
84     if (!$isNested) {
85       $service_ids = $container->getServiceIds();
86       sort($service_ids);
87       foreach ($service_ids as $service_id) {
88         $service = $container->get($service_id);
89         $array[BaseCaster::PREFIX_VIRTUAL . $service_id] = is_object($service) ? get_class($service) : $service;
90       }
91     }
92
93     return $array;
94   }
95
96 }