1 | <?php |
||
42 | class TemplateRenderer |
||
43 | { |
||
44 | |||
45 | /** |
||
46 | * An array of loaded template engine instances. |
||
47 | * @var array<\ntentan\honam\TemplateEngine> |
||
48 | */ |
||
49 | private $loadedInstances; |
||
50 | |||
51 | /** |
||
52 | * Instance of the engine registry for loading template engines. |
||
53 | * @var EngineRegistry |
||
54 | */ |
||
55 | private $registry; |
||
56 | |||
57 | /** |
||
58 | * Instance of the template file resolver for finding template files. |
||
59 | * @var TemplateFileResolver |
||
60 | */ |
||
61 | private $templateFileResolver; |
||
62 | |||
63 | private $tempDirectory; |
||
64 | |||
65 | /** |
||
66 | * TemplateRenderer constructor. |
||
67 | * |
||
68 | * @param EngineRegistry $registry |
||
69 | * @param TemplateFileResolver $templateFileResolver |
||
70 | */ |
||
71 | public function __construct(EngineRegistry $registry, TemplateFileResolver $templateFileResolver) |
||
77 | |||
78 | /** |
||
79 | * @param $templateFile |
||
80 | * @return string|null |
||
|
|||
81 | * @throws UnknownTemplateExtensionException |
||
82 | */ |
||
83 | private function getTemplateExtension($templateFile) |
||
91 | |||
92 | |||
93 | /** |
||
94 | * Check if an engine exists that can render the given file. |
||
95 | * @param $templateFile |
||
96 | * @return bool |
||
97 | * @throws UnknownTemplateExtensionException |
||
98 | */ |
||
99 | public function canRender($templateFile) |
||
103 | |||
104 | |||
105 | /** |
||
106 | * Load and cache an instance of the a template engine. |
||
107 | * |
||
108 | * @param $extension |
||
109 | * @return mixed |
||
110 | * @throws exceptions\TemplateEngineNotFoundException |
||
111 | */ |
||
112 | private function loadEngine($extension) |
||
119 | |||
120 | public function setTempDirectory(string $tempDirectory) |
||
124 | |||
125 | public function getTempDirectory() |
||
129 | |||
130 | |||
131 | /** |
||
132 | * Renders a given template reference with associated template data. This render |
||
133 | * function combs through the template directory heirachy to find a template |
||
134 | * file which matches the given template reference and uses it for the purpose |
||
135 | * of rendering the view. |
||
136 | * |
||
137 | * @param string $template The template reference file. |
||
138 | * @param $data |
||
139 | * @param bool $fromString |
||
140 | * @param null $extension |
||
141 | * @return string |
||
142 | * @throws TemplateResolutionException |
||
143 | * @throws UnknownTemplateExtensionException |
||
144 | * @throws exceptions\TemplateEngineNotFoundException |
||
145 | */ |
||
146 | public function render($template, $data, $fromString = false, $extension=null) |
||
157 | } |
||
158 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.