Total Complexity | 6 |
Total Lines | 71 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 2 | Features | 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 |
||
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 string $blocks |
||
47 | * |
||
48 | * @return void |
||
49 | * |
||
50 | * @throws Exception |
||
51 | */ |
||
52 | public function render(array $fields, array $attributes, string $blocks): void |
||
53 | { |
||
54 | $globalVariables = compact('fields', 'attributes', 'blocks'); |
||
55 | $localVariables = $this->with($fields); |
||
|
|||
56 | |||
57 | $data = array_merge($globalVariables, $localVariables); |
||
58 | |||
59 | echo static::capture($this->template(), $data); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Get the block's template. |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | protected function template(): string |
||
79 | } |
||
80 | } |
||
81 |