You are here

protected function Interpolator::findTokens in Drupal 10

Same name and namespace in other branches
  1. 8 composer/Plugin/Scaffold/Interpolator.php \Drupal\Composer\Plugin\Scaffold\Interpolator::findTokens()
  2. 9 composer/Plugin/Scaffold/Interpolator.php \Drupal\Composer\Plugin\Scaffold\Interpolator::findTokens()

Finds all of the tokens in the provided message.

Parameters

string $message: String with tokens.

Return value

string[] map of token to key, e.g. {{key}} => key

1 call to Interpolator::findTokens()
Interpolator::replacements in composer/Plugin/Scaffold/Interpolator.php
Finds the tokens that exist in a message and builds a replacement array.

File

composer/Plugin/Scaffold/Interpolator.php, line 144

Class

Interpolator
Injects config values from an associative array into a string.

Namespace

Drupal\Composer\Plugin\Scaffold

Code

protected function findTokens($message) {
  $reg_ex = '#' . $this->startToken . '([a-zA-Z0-9._-]+)' . $this->endToken . '#';
  if (!preg_match_all($reg_ex, $message, $matches, PREG_SET_ORDER)) {
    return [];
  }
  $tokens = [];
  foreach ($matches as $matchSet) {
    [
      $sourceText,
      $key,
    ] = $matchSet;
    $tokens[$sourceText] = $key;
  }
  return $tokens;
}