You are here

public static function ResourceFieldEntityReference::subRequest in RESTful 7.2

Creates a request object for the sub-request.

Parameters

array $value: An associative array containing the values to set in the nested call, and information about how to create the request object.

Return value

RequestInterface The request object.

Overrides ResourceFieldEntityReferenceInterface::subRequest

1 call to ResourceFieldEntityReference::subRequest()
ResourceFieldEntityReference::mergeEntityFromReference in src/Plugin/resource/Field/ResourceFieldEntityReference.php
Helper function; Create an entity from a a sub-resource.

File

src/Plugin/resource/Field/ResourceFieldEntityReference.php, line 126
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntityReference.

Class

ResourceFieldEntityReference
Class ResourceFieldEntityReference.

Namespace

Drupal\restful\Plugin\resource\Field

Code

public static function subRequest(array $value) {
  if (empty($value['request'])) {
    throw new BadRequestException('Malformed body payload. Missing "request" key for the sub-request.');
  }
  if (empty($value['request']['method'])) {
    throw new BadRequestException('Malformed body payload. Missing "method" int the "request" key for the sub-request.');
  }
  $request_user_info = $value['request'] + array(
    'path' => NULL,
    'query' => array(),
    'csrf_token' => NULL,
  );
  $headers = empty($request_user_info['headers']) ? array() : $request_user_info['headers'];
  $request_user_info['headers'] = new HttpHeaderBag($headers);
  $request_user_info['via_router'] = FALSE;
  $request_user_info['cookies'] = $_COOKIE;
  $request_user_info['files'] = $_FILES;
  $request_user_info['server'] = $_SERVER;
  return Request::create($request_user_info['path'], $request_user_info['query'], $request_user_info['method'], $request_user_info['headers'], $request_user_info['via_router'], $request_user_info['csrf_token'], $request_user_info['cookies'], $request_user_info['files'], $request_user_info['server']);
}