public static function VarUtils::resolve

Resolves variable placeholders.

Parameters

string $template A template string:

array $vars Variable names:

array $values Variable values:

Return value

string The resolved string

Throws

\InvalidArgumentException If there is a variable with no value

5 calls to VarUtils::resolve()
AssetWriter::writeAsset in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/AssetWriter.php
FileAsset::getLastModified in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Asset/FileAsset.php
Returns the time the current asset was last modified.
FileAsset::load in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Asset/FileAsset.php
Loads the asset into memory and applies load filters.
GlobAsset::initialize in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Asset/GlobAsset.php
Initializes the collection based on the glob(s) passed in.
HttpAsset::load in drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Asset/HttpAsset.php
Loads the asset into memory and applies load filters.

File

drupal/core/vendor/kriswallsmith/assetic/src/Assetic/Util/VarUtils.php, line 32

Class

VarUtils
Variable utilities.

Namespace

Assetic\Util

Code

public static function resolve($template, array $vars, array $values) {
  $map = array();
  foreach ($vars as $var) {
    if (false === strpos($template, '{' . $var . '}')) {
      continue;
    }
    if (!isset($values[$var])) {
      throw new \InvalidArgumentException(sprintf('The path "%s" contains the variable "%s", but was not given any value for it.', $template, $var));
    }
    $map['{' . $var . '}'] = $values[$var];
  }
  return strtr($template, $map);
}