ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Assetic\Util\VarUtils Class Reference

Variable utilities. More...

+ Collaboration diagram for Assetic\Util\VarUtils:

Static Public Member Functions

static resolve ($template, array $vars, array $values)
 Resolves variable placeholders. More...
 
static getCombinations (array $vars, array $values)
 

Private Member Functions

 __construct ()
 

Detailed Description

Variable utilities.

Author
Johannes M. Schmitt schmi.nosp@m.ttjo.nosp@m.h@gma.nosp@m.il.c.nosp@m.om

Definition at line 19 of file VarUtils.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Util\VarUtils::__construct ( )
finalprivate

Definition at line 81 of file VarUtils.php.

82 {
83 }

Member Function Documentation

◆ getCombinations()

static Assetic\Util\VarUtils::getCombinations ( array  $vars,
array  $values 
)
static

Definition at line 50 of file VarUtils.php.

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 }

◆ resolve()

static Assetic\Util\VarUtils::resolve (   $template,
array  $vars,
array  $values 
)
static

Resolves variable placeholders.

Parameters
string$templateA template string
array$varsVariable names
array$valuesVariable values
Returns
string The resolved string
Exceptions

InvalidArgumentException If there is a variable with no value

Definition at line 32 of file VarUtils.php.

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 }
sprintf('%.4f', $callTime)

References sprintf.

Referenced by Assetic\Asset\FileAsset\getLastModified(), Assetic\Asset\GlobAsset\initialize(), Assetic\Asset\FileAsset\load(), and Assetic\Asset\HttpAsset\load().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: