You are here

protected function JsonPathReplacer::validateJsonPathReplacements in Subrequests 8.2

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

Validates tha the JSONPath query yields a string or an array of strings.

Parameters

array $to_replace: The replacement candidates.

Throws

\Symfony\Component\HttpKernel\Exception\BadRequestHttpException When the replacements are not valid.

1 call to JsonPathReplacer::validateJsonPathReplacements()
JsonPathReplacer::addReplacementsForSubject in src/JsonPathReplacer.php
Fill replacement values for a subrequest a subject and an structured token.

File

src/JsonPathReplacer.php, line 384

Class

JsonPathReplacer

Namespace

Drupal\subrequests

Code

protected function validateJsonPathReplacements($to_replace) {
  $is_valid = is_array($to_replace) && array_reduce($to_replace, function ($valid, $replacement) {
    return $valid && (is_string($replacement) || is_int($replacement) || is_bool($replacement) || is_float($replacement));
  }, TRUE);
  if (!$is_valid) {
    throw new BadRequestHttpException(sprintf('The replacement token did find not a list of strings. Instead it found %s.', Json::encode($to_replace)));
  }
}