7e806b5aa57fdf63017d9d7e7112515d8a1be817
[yaffs-website] / vendor / drush / drush / src / 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     /**
19      * Casts \Drupal\Core\Entity\ContentEntityInterface classes.
20      */
21     public static function castContentEntity($entity, $array, $stub, $isNested)
22     {
23         if (!$isNested) {
24             foreach ($entity as $property => $item) {
25                 $array[BaseCaster::PREFIX_PROTECTED . $property] = $item;
26             }
27         }
28
29         return $array;
30     }
31
32     /**
33      * Casts \Drupal\Core\Field\FieldItemListInterface classes.
34      */
35     public static function castFieldItemList($list_item, $array, $stub, $isNested)
36     {
37         if (!$isNested) {
38             foreach ($list_item as $delta => $item) {
39                 $array[BaseCaster::PREFIX_VIRTUAL . $delta] = $item;
40             }
41         }
42
43         return $array;
44     }
45
46     /**
47      * Casts \Drupal\Core\Field\FieldItemInterface classes.
48      */
49     public static function castFieldItem($item, $array, $stub, $isNested)
50     {
51         if (!$isNested) {
52             $array[BaseCaster::PREFIX_VIRTUAL . 'value'] = $item->getValue();
53         }
54
55         return $array;
56     }
57
58     /**
59      * Casts \Drupal\Core\Config\Entity\ConfigEntityInterface classes.
60      */
61     public static function castConfigEntity($entity, $array, $stub, $isNested)
62     {
63         if (!$isNested) {
64             foreach ($entity->toArray() as $property => $value) {
65                 $array[BaseCaster::PREFIX_PROTECTED . $property] = $value;
66             }
67         }
68
69         return $array;
70     }
71
72     /**
73      * Casts \Drupal\Core\Config\ConfigBase classes.
74      */
75     public static function castConfig($config, $array, $stub, $isNested)
76     {
77         if (!$isNested) {
78             foreach ($config->get() as $property => $value) {
79                 $array[BaseCaster::PREFIX_VIRTUAL . $property] = $value;
80             }
81         }
82
83         return $array;
84     }
85
86     /**
87      * Casts \Drupal\Component\DependencyInjection\Container classes.
88      */
89     public static function castContainer($container, $array, $stub, $isNested)
90     {
91         if (!$isNested) {
92             $service_ids = $container->getServiceIds();
93             sort($service_ids);
94             foreach ($service_ids as $service_id) {
95                 $service = $container->get($service_id);
96                 $array[BaseCaster::PREFIX_VIRTUAL . $service_id] = is_object($service) ? get_class($service) : $service;
97             }
98         }
99
100         return $array;
101     }
102
103     /**
104      * Casts \Drupal\Component\Render\MarkupInterface classes.
105      */
106     public static function castMarkup($markup, $array, $stub, $isNested)
107     {
108         if (!$isNested) {
109             $array[BaseCaster::PREFIX_VIRTUAL . 'markup'] = (string) $markup;
110         }
111
112         return $array;
113     }
114 }