Conditions | 6 |
Paths | 17 |
Total Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
24 | function interpolate( |
||
25 | string $string, |
||
26 | array $values, |
||
27 | string $prefix = '{', |
||
28 | string $postfix = '}' |
||
29 | ): string { |
||
30 | $replaces = []; |
||
31 | foreach ($values as $key => $value) { |
||
32 | $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; |
||
33 | |||
34 | try { |
||
35 | //Object as string |
||
36 | $value = is_object($value) ? (string)$value : $value; |
||
37 | } catch (\Exception $e) { |
||
38 | $value = ''; |
||
39 | } |
||
40 | |||
41 | $replaces[$prefix . $key . $postfix] = $value; |
||
42 | } |
||
43 | |||
44 | return strtr($string, $replaces); |
||
45 | } |
||
46 |