Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
MicroTemplateEngine.php
Go to the documentation of this file.
1<?php
2
4
8
10 private string $viewsFolder;
11 private array $parsers = [];
12
13 private function getTemplateParser(string $viewName): TemplateParser {
14 if (!isset ($this->parsers [$viewName])) {
15 $this->parsers [$viewName] = new TemplateParser ($this->viewsFolder . $viewName);
16 }
17 return $this->parsers [$viewName];
18 }
19
20 public function __construct() {
21 $this->viewsFolder = \ROOT . \DS . 'views' . \DS;
22 }
23
24 /*
25 * (non-PHPdoc)
26 * @see TemplateEngine::render()
27 */
28 public function render(string $viewName, ?array $pData = [], bool $asString = false) {
29 if (\is_array($pData)) {
30 \extract($pData);
31 }
32 $content = eval ('?>' . $this->getTemplateParser($viewName)->__toString());
33 if ($asString) {
34 return $content;
35 }
36 echo $content;
37 }
38
39 public function getBlockNames(string $templateName): array {
40 return [];
41 }
42
43 public function getCode(string $templateName): string {
44 $fileName = $this->viewsFolder . $templateName;
45 return UFileSystem::load($fileName);
46 }
47
48 public function exists(string $name): bool {
49 $filename = $this->viewsFolder . $name;
50 return \file_exists($filename);
51 }
52
53 public function addFunction(string $name, $callback, array $options = []): void {
54 throw new \BadMethodCallException('addFunction method has no sense with MicroTemplateEngine');
55 }
56
57 protected function addFilter(string $name, $callback, array $options = []): void {
58 throw new \BadMethodCallException('addFilter method has no sense with MicroTemplateEngine');
59 }
60
61 protected function addExtension($extension): void {
62 throw new \BadMethodCallException('addExtension method has no sense with MicroTemplateEngine');
63 }
64
65 public function getGenerator(): ?TemplateGenerator {
66 return null;
67 }
68}
File system utilities Ubiquity\utils\base$UFileSystem This class is part of Ubiquity.
Ubiquity abstract TemplateGenerator class.
getBlockNames(string $templateName)
Returns the defined block names.
addFilter(string $name, $callback, array $options=[])
getCode(string $templateName)
Returns the source code of the template.
addFunction(string $name, $callback, array $options=[])
render(string $viewName, ?array $pData=[], bool $asString=false)
Renders a view.
exists(string $name)
Checks if we have the source code of a template, given its name.