in src/Serializer.php [127:218]
public static function serializeInput(RequestModel $request, OperationInput $input, array $customSerializer = []): OperationInput
{
$ro = new \ReflectionObject($request);
//headers
$hp = $ro->getProperty('headers');
$hp->setAccessible(true);
$h = $hp->getValue($request);
if (is_array($h)) {
foreach ($h as $key => $value) {
$input->setHeader($key, (string)$value);
}
}
//parameters
$pp = $ro->getProperty('parameters');
$pp->setAccessible(true);
$p = $pp->getValue($request);
if (is_array($p)) {
foreach ($p as $key => $value) {
$input->setParameter($key, (string) $value);
}
}
//payload
$pd = $ro->getProperty('payload');
$pd->setAccessible(true);
$payload = $pd->getValue($request);
if ($payload instanceof StreamInterface) {
$input->setBody($payload);
}
// all properties in request
foreach ($ro->getProperties() as $property) {
$property->setAccessible(true);
$val = $property->getValue($request);
if (!isset($val)) {
if (Functions::isRequiredProperty($property)) {
throw new \InvalidArgumentException('missing required field, ' . $property->getName() . '.');
}
continue;
}
$annotation = Functions::getTagAnnotation($property);
if ($annotation == null) {
continue;
}
switch ($annotation->position) {
case 'query':
$input->setParameter(
$annotation->rename,
self::castToString($val, $annotation->format)
);
break;
case 'header':
if ($annotation->format === 'usermeta' && \is_array($val)) {
//user metadata
foreach ($val as $k => $v) {
$input->setHeader(
(string)$annotation->rename . $k,
(string)$v
);
}
} else {
$input->setHeader(
$annotation->rename,
self::castToString($val, $annotation->format)
);
}
break;
case 'body':
$body = $val;
if ($annotation->type === 'xml') {
$body = self::serializeXml($val, $annotation->rename);
}
$input->setBody(Utils::streamFor($body));
break;
};
}
// custom serializer
foreach ($customSerializer as $serializer) {
if (\is_callable($serializer)) {
$serializer($request, $input);
} else {
call_user_func($serializer, $request, $input);
}
}
return $input;
}