You are here

protected function JsonPathReplacer::findTokens in Subrequests 8.2

Same name and namespace in other branches
  1. 3.x src/JsonPathReplacer.php \Drupal\subrequests\JsonPathReplacer::findTokens()

Finds and parses all the tokens in a given string.

@returns array A list of all the matches. Each match contains the token, the subject to search replacements in and the JSONPath query to execute.

Parameters

string $subject: The tokenized string. This is usually the URI or the serialized body.

1 call to JsonPathReplacer::findTokens()
JsonPathReplacer::extractTokenReplacements in src/JsonPathReplacer.php
Extracts the token replacements for a given subrequest.

File

src/JsonPathReplacer.php, line 329

Class

JsonPathReplacer

Namespace

Drupal\subrequests

Code

protected function findTokens($subject) {
  $matches = [];
  $pattern = '/\\{\\{([^\\{\\}]+\\.[^\\{\\}]+)@([^\\{\\}]+)\\}\\}/';
  preg_match_all($pattern, $subject, $matches);
  if (!($matches = array_filter($matches))) {
    return [];
  }
  $output = [];
  for ($index = 0; $index < count($matches[0]); $index++) {

    // We only care about the first three items: full match, subject ID and
    // JSONPath query.
    $output[] = [
      $matches[0][$index],
      $matches[1][$index],
      $matches[2][$index],
    ];
  }
  return $output;
}