1 | <?php |
||
41 | class TemplateRenderer |
||
42 | { |
||
43 | |||
44 | /** |
||
45 | * An array of loaded template engine instances. |
||
46 | * @var array<\ntentan\honam\TemplateEngine> |
||
47 | */ |
||
48 | private $loadedInstances; |
||
49 | |||
50 | /** |
||
51 | * Instance of the engine registry for loading template engines. |
||
52 | * @var EngineRegistry |
||
53 | */ |
||
54 | private $registry; |
||
55 | |||
56 | /** |
||
57 | * Instance of the template file resolver for finding template files. |
||
58 | * @var TemplateFileResolver |
||
59 | */ |
||
60 | private $templateFileResolver; |
||
61 | |||
62 | /** |
||
63 | * TemplateRenderer constructor. |
||
64 | * |
||
65 | * @param EngineRegistry $registry |
||
66 | */ |
||
67 | public function __construct(EngineRegistry $registry, TemplateFileResolver $templateFileResolver) |
||
73 | |||
74 | /** |
||
75 | * @return string|null |
||
|
|||
76 | */ |
||
77 | private function getTemplateExtension($templateFile) |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Check if an engine exists that can render the given file. |
||
88 | * @param $file |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function canRender($templateFile) |
||
95 | |||
96 | |||
97 | /** |
||
98 | * Load and cache an instance of the a template engine. |
||
99 | * |
||
100 | * @param $extension |
||
101 | * @return mixed |
||
102 | * @throws exceptions\TemplateEngineNotFoundException |
||
103 | */ |
||
104 | private function loadEngine($extension) |
||
111 | |||
112 | |||
113 | /** |
||
114 | * Renders a given template reference with associated template data. This render |
||
115 | * function combs through the template directory heirachy to find a template |
||
116 | * file which matches the given template reference and uses it for the purpose |
||
117 | * of rendering the view. |
||
118 | * |
||
119 | * @param string $template The template reference file. |
||
120 | * @param array $templateData The data to be passed to the template. |
||
121 | * @return string |
||
122 | * @throws \ntentan\honam\exceptions\FileNotFoundException |
||
123 | */ |
||
124 | public function render($template, $data, $fromString = false, $extension=null) |
||
135 | } |
||
136 |
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.