function ReflectionCaster::castParameter
File
-
vendor/
symfony/ var-dumper/ Caster/ ReflectionCaster.php, line 274
Class
- ReflectionCaster
- Casts Reflector related classes to array representation.
Namespace
Symfony\Component\VarDumper\CasterCode
public static function castParameter(\ReflectionParameter $c, array $a, Stub $stub, bool $isNested) : array {
$prefix = Caster::PREFIX_VIRTUAL;
self::addMap($a, $c, [
'position' => 'getPosition',
'isVariadic' => 'isVariadic',
'byReference' => 'isPassedByReference',
'allowsNull' => 'allowsNull',
]);
self::addAttributes($a, $c, $prefix);
if ($v = $c->getType()) {
$a[$prefix . 'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : (string) $v;
}
if (isset($a[$prefix . 'typeHint'])) {
$v = $a[$prefix . 'typeHint'];
$a[$prefix . 'typeHint'] = new ClassStub($v, [
class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '',
'',
]);
}
else {
unset($a[$prefix . 'allowsNull']);
}
if ($c->isOptional()) {
try {
$a[$prefix . 'default'] = $v = $c->getDefaultValue();
if ($c->isDefaultValueConstant() && !\is_object($v)) {
$a[$prefix . 'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
}
if (null === $v) {
unset($a[$prefix . 'allowsNull']);
}
} catch (\ReflectionException) {
}
}
return $a;
}