| 1 | <?php |
||
| 16 | class Interpolator |
||
| 17 | { |
||
| 18 | 2 | public function interpolate(&$data) |
|
| 19 | { |
||
| 20 | 2 | if (is_array($data)) { |
|
| 21 | 2 | foreach ($data as &$item) { |
|
| 22 | 2 | $this->interpolate($item); |
|
| 23 | 2 | } |
|
| 24 | 2 | } elseif (is_string($data)) { |
|
| 25 | 2 | $data = preg_replace_callback('/\\$(\\w+)\\[\'(.+?)\'\\]/', function ($matches) { |
|
| 26 | return $this->get($matches[1], $matches[2]); |
||
| 27 | 2 | }, $data); |
|
| 28 | 2 | } |
|
| 29 | 2 | } |
|
| 30 | |||
| 31 | public function get($scope, $name) |
||
| 43 | |||
| 44 | public function getConfig($name) |
||
| 50 | } |
||
| 51 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: