| Conditions | 5 |
| Paths | 9 |
| Total Lines | 28 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | public function render($template, array $data = []) |
||
| 38 | { |
||
| 39 | if (isset($data['template'])) { |
||
| 40 | throw new \InvalidArgumentException('Duplicate template key found'); |
||
| 41 | } |
||
| 42 | |||
| 43 | if (!is_file($this->templatePath.$template)) { |
||
| 44 | throw new \RuntimeException(sprintf('View cannot render template `%s` because it does not exist', $template)); |
||
| 45 | } |
||
| 46 | |||
| 47 | $data = array_merge($this->attributes, $data); |
||
| 48 | |||
| 49 | try { |
||
| 50 | ob_start(); |
||
| 51 | $this->protectedIncludeScope($this->templatePath.$template, $data); |
||
| 52 | $output = ob_get_clean(); |
||
| 53 | } catch (\Throwable $e) { |
||
| 54 | // PHP 7+ |
||
| 55 | ob_end_clean(); |
||
| 56 | throw $e; |
||
| 57 | } catch (\Exception $e) { |
||
| 58 | // PHP < 7 |
||
| 59 | ob_end_clean(); |
||
| 60 | throw $e; |
||
| 61 | } |
||
| 62 | |||
| 63 | return $output; |
||
| 64 | } |
||
| 65 | |||
| 76 |