| Total Complexity | 5 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 95% |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class NativePHPRenderer implements RendererInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Root folder for the template files |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $templateRoot; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Constructor |
||
| 26 | * |
||
| 27 | * @var string $templateRoot |
||
| 28 | */ |
||
| 29 | 1 | public function __construct(string $templateRoot) |
|
| 30 | { |
||
| 31 | 1 | $this->templateRoot = $templateRoot; |
|
| 32 | 1 | } |
|
| 33 | |||
| 34 | /** |
||
| 35 | * Gets the template file from the view DTO object |
||
| 36 | * |
||
| 37 | * @param \Phauthentic\Presentation\Renderer\ViewInterface |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | 1 | public function getTemplateFile(ViewInterface $view): string |
|
| 41 | { |
||
| 42 | 1 | $path = $view->getTemplatePath(); |
|
| 43 | 1 | $path = Utility::sanitizePath($path); |
|
| 44 | |||
| 45 | 1 | $template = $this->templateRoot . DIRECTORY_SEPARATOR . $path . $view->getTemplate() . '.php'; |
|
| 46 | |||
| 47 | 1 | if (!is_file($template)) { |
|
| 48 | throw new MissingTemplateException('Template file missing: ' . $template); |
||
| 49 | } |
||
| 50 | |||
| 51 | 1 | return $template; |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @inheritDoc |
||
| 56 | */ |
||
| 57 | 1 | public function renderTemplate($template, $viewVars): string |
|
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @inheritDoc |
||
| 70 | */ |
||
| 71 | 1 | public function render(ViewInterface $view): string |
|
| 78 |