1 | <?php |
||
17 | abstract class AbstractEngine implements EngineInterface |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @var LoaderInterface |
||
22 | */ |
||
23 | private $loader; |
||
24 | |||
25 | /** |
||
26 | * The cache option. |
||
27 | * |
||
28 | * @var mixed |
||
29 | */ |
||
30 | private $cache; |
||
31 | |||
32 | /** |
||
33 | * Build the object with an array of dependencies. |
||
34 | * |
||
35 | * ## Required parameters: |
||
36 | * - `loader` a Loader object, to load templates. |
||
37 | * |
||
38 | * @param array $data Engine dependencie. |
||
39 | */ |
||
40 | public function __construct(array $data) |
||
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | abstract public function type(): string; |
||
53 | |||
54 | /** |
||
55 | * Render a template (from ident) with a given context. |
||
56 | * |
||
57 | * @param string $templateIdent The template identifier to load and render. |
||
58 | * @param mixed $context The rendering context. |
||
59 | * @return string The rendered template string. |
||
60 | */ |
||
61 | public function render(string $templateIdent, $context): string |
||
66 | |||
67 | /** |
||
68 | * @param string $templateString The template string to render. |
||
69 | * @param mixed $context The rendering context. |
||
70 | * @return string The rendered template string. |
||
71 | */ |
||
72 | abstract public function renderTemplate(string $templateString, $context): string; |
||
73 | |||
74 | /** |
||
75 | * Delegates template loading to the engine's Loader object. |
||
76 | * |
||
77 | * @param string $templateIdent The template identifier to load. |
||
78 | * @return string The template string, loaded from identifier. |
||
79 | */ |
||
80 | public function loadTemplate(string $templateIdent): string |
||
84 | |||
85 | /** |
||
86 | * @param string $varName The name of the variable to set this template unto. |
||
87 | * @param string|null $templateIdent The "dynamic template" to set. null to clear. |
||
88 | * @return void |
||
89 | */ |
||
90 | public function setDynamicTemplate(string $varName, ?string $templateIdent): void |
||
94 | |||
95 | /** |
||
96 | * Set the engine's cache implementation. |
||
97 | * |
||
98 | * @param mixed $cache A engine cache implementation, |
||
99 | * an absolute path to the compiled views, |
||
100 | * a boolean to enable/disable cache. |
||
101 | * @return void |
||
102 | */ |
||
103 | protected function setCache($cache): void |
||
107 | |||
108 | /** |
||
109 | * Get the engine's cache implementation. |
||
110 | * |
||
111 | * @return mixed |
||
112 | */ |
||
113 | protected function cache() |
||
117 | |||
118 | |||
119 | /** |
||
120 | * @return LoaderInterface |
||
121 | */ |
||
122 | protected function loader() : LoaderInterface |
||
126 | |||
127 | |||
128 | |||
129 | /** |
||
130 | * @param LoaderInterface $loader A loader instance. |
||
131 | * @return void |
||
132 | */ |
||
133 | private function setLoader(LoaderInterface $loader): void |
||
137 | } |
||
138 |