You are here

protected function JsonPathReplacer::replaceTokenSubject in Subrequests 8.2

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

Does the replacement on the token subject.

@returns string The replaced string.

Parameters

string $token: The thing to replace.

string $value: The thing to replace it with.

string $token_subject: The thing to replace it on.

1 call to JsonPathReplacer::replaceTokenSubject()
JsonPathReplacer::doReplaceTokensInLocation in src/JsonPathReplacer.php
Creates replacements for either the body or the URI.

File

src/JsonPathReplacer.php, line 143

Class

JsonPathReplacer

Namespace

Drupal\subrequests

Code

protected function replaceTokenSubject($token, $value, $token_subject) {

  // Escape regular expression.
  if (is_int($value) || is_float($value) || is_bool($value)) {
    if (is_bool($value)) {
      $value = $value ? 'true' : 'false';
    }
    $regexp = sprintf('/%s/', preg_quote("\"{$token}\""), '/');
    $token_subject = preg_replace($regexp, $value, $token_subject);
  }
  $regexp = sprintf('/%s/', preg_quote($token), '/');
  return preg_replace($regexp, $value, $token_subject);
}