Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Template | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| bind | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| templatedVars | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Projom\Util; |
| 6 | |
| 7 | class Template |
| 8 | { |
| 9 | public static function bind(string $template, array $vars): string |
| 10 | { |
| 11 | $replacementVars = array_values($vars); |
| 12 | $templatedVars = static::templatedVars(array_keys($vars)); |
| 13 | return str_replace($templatedVars, $replacementVars, $template); |
| 14 | } |
| 15 | |
| 16 | public static function templatedVars(array $subjects, string $prefix = '{{', string $postfix = '}}'): array |
| 17 | { |
| 18 | $prefixedSubjects = preg_filter('/^/', $prefix, $subjects); |
| 19 | return preg_filter('/$/', $postfix, $prefixedSubjects); |
| 20 | } |
| 21 | } |