Conditions | 7 |
Paths | 4 |
Total Lines | 36 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
29 | private function resolveValue(ContainerInterface $container, $value) |
||
30 | { |
||
31 | if (is_array($value)) { |
||
32 | foreach ($value as $key => $val) { |
||
33 | $value[$key] = $this->resolveValue($container, $val); |
||
34 | } |
||
35 | |||
36 | return $value; |
||
37 | } |
||
38 | |||
39 | if (!is_string($value)) { |
||
40 | return $value; |
||
41 | } |
||
42 | |||
43 | $escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($container, $value) { |
||
44 | // skip %% |
||
45 | if (!isset($match[1])) { |
||
46 | return '%%'; |
||
47 | } |
||
48 | |||
49 | $resolved = $container->getParameter($match[1]); |
||
50 | if (is_string($resolved) || is_numeric($resolved)) { |
||
51 | return (string) $resolved; |
||
52 | } |
||
53 | |||
54 | throw new \RuntimeException(sprintf( |
||
55 | 'The container parameter "%s" must be a string or numeric, but it is of type %s.', |
||
56 | $match[1], |
||
57 | $value, |
||
58 | gettype($resolved) |
||
59 | ) |
||
60 | ); |
||
61 | }, $value); |
||
62 | |||
63 | return str_replace('%%', '%', $escapedValue); |
||
64 | } |
||
65 | } |
||
66 |