-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1787 from damiankloip/psysh-caster-class
Move caster callbacks into a Caster class
- Loading branch information
Showing
2 changed files
with
85 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drush\Psysh\Caster. | ||
*/ | ||
|
||
namespace Drush\Psysh; | ||
|
||
use Symfony\Component\VarDumper\Caster\Caster as BaseCaster; | ||
|
||
/** | ||
* Caster class for VarDumper casters for the shell. | ||
*/ | ||
class Caster { | ||
|
||
/** | ||
* Casts \Drupal\Core\Entity\ContentEntityInterface classes. | ||
*/ | ||
public static function castContentEntity($entity, $array, $stub, $isNested) { | ||
if (!$isNested) { | ||
foreach ($entity as $property => $item) { | ||
$array[BaseCaster::PREFIX_PROTECTED . $property] = $item; | ||
} | ||
} | ||
|
||
return $array; | ||
} | ||
|
||
/** | ||
* Casts \Drupal\Core\Field\FieldItemListInterface classes. | ||
*/ | ||
public static function castFieldItemList($list_item, $array, $stub, $isNested) { | ||
if (!$isNested) { | ||
foreach ($list_item as $delta => $item) { | ||
$array[BaseCaster::PREFIX_VIRTUAL . $delta] = $item; | ||
} | ||
} | ||
|
||
return $array; | ||
} | ||
|
||
/** | ||
* Casts \Drupal\Core\Field\FieldItemInterface classes. | ||
*/ | ||
public static function castFieldItem($item, $array, $stub, $isNested) { | ||
if (!$isNested) { | ||
$array[BaseCaster::PREFIX_VIRTUAL . 'value'] = $item->getValue(); | ||
} | ||
|
||
return $array; | ||
} | ||
|
||
/** | ||
* Casts \Drupal\Core\Config\Entity\ConfigEntityInterface classes. | ||
*/ | ||
public static function castConfigEntity($entity, $array, $stub, $isNested) { | ||
if (!$isNested) { | ||
foreach ($entity->toArray() as $property => $value) { | ||
$array[BaseCaster::PREFIX_PROTECTED . $property] = $value; | ||
} | ||
} | ||
|
||
return $array; | ||
} | ||
|
||
/** | ||
* Casts \Drupal\Core\Config\ConfigBase classes. | ||
*/ | ||
public static function castConfig($config, $array, $stub, $isNested) { | ||
if (!$isNested) { | ||
foreach ($config->get() as $property => $value) { | ||
$array[BaseCaster::PREFIX_VIRTUAL . $property] = $value; | ||
} | ||
} | ||
|
||
return $array; | ||
} | ||
|
||
} |