PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.3
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.3
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / kriswallsmith / assetic / src / Assetic / Util / VarUtils.php

VarUtils.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.3, at vendor/kriswallsmith/assetic/src/Assetic/Util/VarUtils.php

85 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
12 namespace Assetic\Util;
13
14 /**
15 * Variable utilities.
16 *
17 * @author Johannes M. Schmitt <[email protected]>
18 */
19 abstract class VarUtils
20 {
21 /**
22 * Resolves variable placeholders.
23 *
24 * @param string $template A template string
25 * @param array $vars Variable names
26 * @param array $values Variable values
27 *
28 * @return string The resolved string
29 *
30 * @throws \InvalidArgumentException If there is a variable with no value
31 */
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 }
85