php-advanced-json-rpc
php-advanced-json-rpc copied to clipboard
Support for php 8.0 ReflectionUnionType in lib/Dispatcher.php
trafficstars
https://wiki.php.net/rfc/union_types_v2 was merged.
This introduces ReflectionUnionType extends ReflectionType. https://wiki.php.net/rfc/union_types_v2#reflection - ReflectionUnionType->getTypes() should be used if it exists. (similar to how phpdoc union types are used).
The existing code wouldn't work, because $class = (string)$paramType would contain |.
Also, I think that nullable types may get converted to ?stdClass in 8.0 in nullable types of union types
if ($paramType instanceof ReflectionNamedType) {
// We have object data to map and want the class name.
// This should not include the `?` if the type was nullable.
$class = $paramType->getName();
} else {
// Fallback for php 7.0, which is still supported (and doesn't have nullable).
$class = (string)$paramType;
}
$value = $this->mapper->map($value, new $class());