protected static function RequestTree::cloneRequest in Subrequests 8
Clones a request and modifies certain parameters.
We need to do this to reset some of the internal request caches. There may be a better way of doing this, but I could not find it in the time that I expected.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The original request.
$uri: The (potentially) new URI.
$content: The (potentially) new body content.
$id: The subrequest id.
$parent_id: The subrequest id of the parent.
Return value
\Symfony\Component\HttpFoundation\Request The cloned request.
1 call to RequestTree::cloneRequest()
- RequestTree::dereference in src/
Blueprint/ RequestTree.php - Resolves the JSON Pointer references.
File
- src/
Blueprint/ RequestTree.php, line 303
Class
- RequestTree
- Contains the hierarchical information of the requests.
Namespace
Drupal\subrequests\BlueprintCode
protected static function cloneRequest(Request $request, $uri, $content, $id, $parent_id) {
$request->server
->set('REQUEST_URI', $uri);
$sub_tree = $request->attributes
->get(static::SUBREQUEST_TREE);
$session = $request
->getSession();
$new_request = Request::create($uri, $request
->getMethod(), (array) $request->query
->getIterator(), (array) $request->cookies
->getIterator(), (array) $request->files
->getIterator(), (array) $request->server
->getIterator(), $content);
// Set the sub-request headers.
foreach ($request->headers as $key => $val) {
$new_request->headers
->set($key, $val);
}
$new_request->headers
->set('Content-ID', sprintf('<%s>', $id));
$new_request->attributes
->set(static::SUBREQUEST_PARENT_ID, $parent_id);
$new_request->attributes
->set(static::SUBREQUEST_ID, $id);
$new_request->attributes
->set(static::SUBREQUEST_TREE, $sub_tree);
$new_request
->setSession($session);
return $new_request;
}