ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
VarUtils.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Assetic package, an OpenSky project.
5 *
6 * (c) 2010-2014 OpenSky Project Inc
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Assetic\Util;
13
19abstract class VarUtils
20{
32 public static function resolve($template, array $vars, array $values)
33 {
34 $map = array();
35 foreach ($vars as $var) {
36 if (false === strpos($template, '{'.$var.'}')) {
37 continue;
38 }
39
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));
42 }
43
44 $map['{'.$var.'}'] = $values[$var];
45 }
46
47 return strtr($template, $map);
48 }
49
50 public static function getCombinations(array $vars, array $values)
51 {
52 if (!$vars) {
53 return array(array());
54 }
55
56 $combinations = array();
57 $nbValues = array();
58 foreach ($values as $var => $vals) {
59 if (!in_array($var, $vars, true)) {
60 continue;
61 }
62
63 $nbValues[$var] = count($vals);
64 }
65
66 for ($i = array_product($nbValues), $c = $i * 2; $i < $c; $i++) {
67 $k = $i;
68 $combination = array();
69
70 foreach ($vars as $var) {
71 $combination[$var] = $values[$var][$k % $nbValues[$var]];
72 $k = intval($k / $nbValues[$var]);
73 }
74
75 $combinations[] = $combination;
76 }
77
78 return $combinations;
79 }
80
81 final private function __construct()
82 {
83 }
84}
sprintf('%.4f', $callTime)
Variable utilities.
Definition: VarUtils.php:20
static getCombinations(array $vars, array $values)
Definition: VarUtils.php:50
static resolve($template, array $vars, array $values)
Resolves variable placeholders.
Definition: VarUtils.php:32
An exception for terminatinating execution or to throw for unit testing.