Passed
Push — master ( 78312e...d7519e )
by Radu
01:19
created

HtmlOutput::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace WebServCo\Framework\Libraries;
3
4
final class HtmlOutput extends \WebServCo\Framework\AbstractLibrary implements
5
    \WebServCo\Framework\Interfaces\OutputInterface
6
{
7
    private $path;
8
    private $template;
9
    
10
    public function setPath($path)
11
    {
12
        $this->path = $path;
13
        return true;
14
    }
15
    
16
    public function setTemplate($template)
17
    {
18
        $this->template = $template;
19
        return true;
20
    }
21
    
22
    public function render()
23
    {
24
        try {
25
            $templatePath = "{$this->path}{$this->template}.php";
26
            if (!is_file($templatePath)) {
27
                throw new \ErrorException('Template file not found');
28
            }
29
            ob_start();
30
            include $templatePath;
31
            $output = ob_get_clean();
32
        } catch (\Throwable $e) { // php7
33
            ob_end_clean();
34
            throw $e;
35
        } catch (\Exception $e) { // php5
36
            ob_end_clean();
37
            throw $e;
38
        }
39
        return $output;
40
    }
41
}
42