4
* This file is part of the Assetic package, an OpenSky project.
6
* (c) 2010-2013 OpenSky Project Inc
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
12
namespace Assetic\Util;
17
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
19
abstract class VarUtils
22
* Resolves variable placeholders.
24
* @param string $template A template string
25
* @param array $vars Variable names
26
* @param array $values Variable values
28
* @return string The resolved string
30
* @throws \InvalidArgumentException If there is a variable with no value
32
public static function resolve($template, array $vars, array $values)
35
foreach ($vars as $var) {
36
if (false === strpos($template, '{'.$var.'}')) {
40
if (!isset($values[$var])) {
41
throw new \InvalidArgumentException(sprintf('The template "%s" contains the variable "%s", but was not given any value for it.', $template, $var));
44
$map['{'.$var.'}'] = $values[$var];
47
return strtr($template, $map);
50
public static function getCombinations(array $vars, array $values)
53
return array(array());
56
$combinations = array();
58
foreach ($values as $var => $vals) {
59
if (!in_array($var, $vars, true)) {
63
$nbValues[$var] = count($vals);
66
for ($i = array_product($nbValues), $c = $i * 2; $i < $c; $i++) {
68
$combination = array();
70
foreach ($vars as $var) {
71
$combination[$var] = $values[$var][$k % $nbValues[$var]];
72
$k = intval($k / $nbValues[$var]);
75
$combinations[] = $combination;
81
final private function __construct() { }