function FFICaster::castFFIStructLike
File
-
vendor/
symfony/ var-dumper/ Caster/ FFICaster.php, line 145
Class
- FFICaster
- Casts FFI extension classes to array representation.
Namespace
Symfony\Component\VarDumper\CasterCode
private static function castFFIStructLike(CType $type, ?CData $data = null) : array {
$isUnion = ($type->getAttributes() & CType::ATTR_UNION) === CType::ATTR_UNION;
$result = [];
foreach ($type->getStructFieldNames() as $name) {
$field = $type->getStructFieldType($name);
// Retrieving the value of a field from a union containing
// a pointer is not a safe operation, because may contain
// incorrect data.
$isUnsafe = $isUnion && CType::TYPE_POINTER === $field->getKind();
if ($isUnsafe) {
$result[Caster::PREFIX_VIRTUAL . $name . '?'] = $field;
}
elseif (null === $data) {
$result[Caster::PREFIX_VIRTUAL . $name] = $field;
}
else {
$fieldName = $data->{$name} instanceof CData ? '' : $field->getName() . ' ';
$result[Caster::PREFIX_VIRTUAL . $fieldName . $name] = $data->{$name};
}
}
return $result;
}