You are here

protected static function RequestTree::findReplacement in Subrequests 8

Find a replacement in the responses for the JSON pointer.

Parameters

\Symfony\Component\HttpFoundation\Response[] $responses: The array of responses to look data into.

string $id: The response ID to extract data from.

$json_pointer_path: The JSON pointer path of the data to extract.

Return value

mixed The contents of the pointed JSON property.

Throws

\Rs\Json\Pointer\NonexistentValueReferencedException When the referenced response was not found.

1 call to RequestTree::findReplacement()
RequestTree::replaceAllOccurrences in src/Blueprint/RequestTree.php
Do in-place replacements for an input string containing replacement tokens.

File

src/Blueprint/RequestTree.php, line 268

Class

RequestTree
Contains the hierarchical information of the requests.

Namespace

Drupal\subrequests\Blueprint

Code

protected static function findReplacement(array $responses, $id, $json_pointer_path) {
  $found = array_filter($responses, function (Response $response) use ($id) {
    return $response->headers
      ->get('Content-ID') === sprintf('<%s>', $id);
  });
  $response = reset($found);
  if (!$response instanceof Response) {
    throw new NonexistentValueReferencedException('Response is still not ready.');
  }

  // Find the data in the response output.
  $pointer = new Pointer($response
    ->getContent());
  return $pointer
    ->get($json_pointer_path);
}