| Total Complexity | 6 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | trait Renderable |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Captures the output that is generated when a template is included. |
||
| 12 | * This property is static to prevent object scope resolution. |
||
| 13 | * |
||
| 14 | * @param string $template |
||
| 15 | * @param array $data |
||
| 16 | * |
||
| 17 | * @return string |
||
| 18 | * |
||
| 19 | * @throws Exception |
||
| 20 | */ |
||
| 21 | protected static function capture(string $template, array $data): string |
||
| 22 | { |
||
| 23 | extract($data, EXTR_SKIP); |
||
| 24 | |||
| 25 | ob_start(); |
||
| 26 | |||
| 27 | try { |
||
| 28 | include $template; |
||
| 29 | } catch (Exception $e) { |
||
| 30 | ob_end_clean(); |
||
| 31 | |||
| 32 | throw $e; |
||
| 33 | } |
||
| 34 | |||
| 35 | return ob_get_clean(); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Render the block. |
||
| 40 | * |
||
| 41 | * [!!] Global variables with the same key name as local variables will be |
||
| 42 | * overwritten by the local variable. |
||
| 43 | * |
||
| 44 | * @param array $fields |
||
| 45 | * @param array $attributes |
||
| 46 | * @param array $blocks |
||
| 47 | * |
||
| 48 | * @return void |
||
| 49 | * |
||
| 50 | * @throws Exception |
||
| 51 | */ |
||
| 52 | public function render(array $fields, array $attributes, array $blocks): void |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Get the block's template. |
||
| 64 | * |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | protected function template(): string |
||
| 81 |