public function createFromRequest(Request $request, bool $normalization, array $attributes = null) : array
{
if (null === $attributes) {
$attributes = RequestAttributesExtractor::extractAttributes($request);
}
$resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']);
$key = $normalization ? 'normalization_context' : 'denormalization_context';
if (isset($attributes['collection_operation_name'])) {
$context = $resourceMetadata->getCollectionOperationAttribute($attributes['collection_operation_name'], $key, [], true);
$context['collection_operation_name'] = $attributes['collection_operation_name'];
} else {
$context = $resourceMetadata->getItemOperationAttribute($attributes['item_operation_name'], $key, [], true);
$context['item_operation_name'] = $attributes['item_operation_name'];
}
if (!$normalization && !isset($context['api_allow_update'])) {
$context['api_allow_update'] = Request::METHOD_PUT === $request->getMethod();
}
$context['resource_class'] = $attributes['resource_class'];
$context['request_uri'] = $request->getRequestUri();
return $context;
}