protected function RpcRequestFactory::denormalizeParam in JSON-RPC 2.x
Same name and namespace in other branches
- 8 src/Shaper/RpcRequestFactory.php \Drupal\jsonrpc\Shaper\RpcRequestFactory::denormalizeParam()
Denormalizes a single JSON-RPC request object parameter.
Parameters
mixed $argument: The decoded JSON-RPC request parameter to be denormalized.
\Drupal\jsonrpc\ParameterDefinitionInterface $parameter_definition: The JSON-RPC request's parameter definition.
Return value
mixed The denormalized parameter.
Throws
\Drupal\jsonrpc\Exception\JsonRpcException
1 call to RpcRequestFactory::denormalizeParam()
- RpcRequestFactory::denormalizeParams in src/
Shaper/ RpcRequestFactory.php - Denormalizes a JSON-RPC request object's parameters.
File
- src/
Shaper/ RpcRequestFactory.php, line 167
Class
- RpcRequestFactory
- Creates RPC Request objects.
Namespace
Drupal\jsonrpc\ShaperCode
protected function denormalizeParam($argument, ParameterDefinitionInterface $parameter_definition) {
$factory_class = $parameter_definition
->getFactory() ?: RawParameterFactory::class;
$factory = call_user_func_array([
$factory_class,
'create',
], [
$parameter_definition,
$this->container,
]);
$context = new Context([
ParameterDefinitionInterface::class => $parameter_definition,
]);
try {
// TODO: Wrap other shaper transformations in a similar way for nicer
// error outputs.
return $factory
->transform($argument, $context);
} catch (\TypeError $exception) {
$message = "The {$parameter_definition->getId()} parameter does not conform to the parameter schema. {$exception->getMessage()}";
throw JsonRpcException::fromError(Error::invalidParams($message));
}
}