1 | <?php |
||
19 | abstract class AbstractView implements ViewInterface |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @var EngineInterface $engine |
||
24 | */ |
||
25 | private $engine; |
||
26 | |||
27 | /** |
||
28 | * Build the object with an array of dependencies. |
||
29 | * |
||
30 | * @param array $data View class dependencies. |
||
31 | * @throws InvalidArgumentException If required parameters are missing. |
||
32 | */ |
||
33 | public function __construct(array $data) |
||
37 | |||
38 | /** |
||
39 | * Load a template (from identifier). |
||
40 | * |
||
41 | * @param string $templateIdent The template identifier to load.. |
||
42 | * @return string |
||
43 | */ |
||
44 | public function loadTemplate(string $templateIdent): string |
||
51 | |||
52 | /** |
||
53 | * Load a template (from identifier) and render it. |
||
54 | * |
||
55 | * @param string $templateIdent The template identifier, to load and render. |
||
56 | * @param mixed $context The view controller (rendering context). |
||
57 | * @return string |
||
58 | */ |
||
59 | public function render(string $templateIdent, $context = null): string |
||
63 | |||
64 | /** |
||
65 | * Render a template (from string). |
||
66 | * |
||
67 | * @param string $templateString The full template string to render. |
||
68 | * @param mixed $context The view controller (rendering context). |
||
69 | * @return string |
||
70 | */ |
||
71 | public function renderTemplate(string $templateString, $context = null): string |
||
75 | |||
76 | /** |
||
77 | * @param string $varName The name of the variable to set this template unto. |
||
78 | * @param string|null $templateIdent The "dynamic template" to set. null to clear. |
||
79 | * @return void |
||
80 | */ |
||
81 | public function setDynamicTemplate(string $varName, ?string $templateIdent): void |
||
85 | |||
86 | /** |
||
87 | * Get the view's rendering engine instance. |
||
88 | * |
||
89 | * @return EngineInterface |
||
90 | */ |
||
91 | protected function engine(): EngineInterface |
||
95 | |||
96 | /** |
||
97 | * Set the engine (`EngineInterface`) dependency. |
||
98 | * |
||
99 | * @param EngineInterface $engine The rendering engine. |
||
100 | * @return void |
||
101 | */ |
||
102 | private function setEngine(EngineInterface $engine): void |
||
106 | } |
||
107 |