Passed
Branch master (a48404)
by Henri
01:21
created

Viewer::include()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace HnrAzevedo\Viewer;
4
5
class Viewer{
6
    use HelperTrait, CheckTrait;
7
8
    private static $instance = null;
9
    private string $path = '';
10
11
    public function __construct(string $path)
12
    {
13
        $this->path = $path;
14
        return $this;
15
    }
16
17
    public static function getInstance(string $path): Viewer
18
    {
19
        if(is_null(self::$instance)){
20
            self::$instance = new self($path);
21
        }
22
        return self::$instance;
23
    }
24
25
    public static function create(string $path): Viewer
26
    {
27
        return self::getInstance($path);
28
    }
29
30
    public function render(string $file, array $data = [], bool $return = false): string
31
    {
32
        header('Content-Type: text/html; charset=utf-8');
33
        
34
        $this->check_viewExist($file);
35
36
        $buffer = $this->getOB($this->path . DIRECTORY_SEPARATOR . $file . '.view.php', $data);
37
        
38
        $buffer = $this->getVars($buffer);
39
        
40
        $buffer = $this->removeComments($buffer);
41
42
        $this->saveData();
43
44
        if(!$return){
45
            echo $buffer;
46
            return '';
47
        }
48
        
49
        return $buffer;
50
    }
51
52
    public function include(string $file): void
53
    {
54
        $buffer = $this->getOB($this->path.$file.'.tpl.php');
55
        $buffer = $this->getVars($buffer);
56
        echo $buffer;
57
    }
58
59
}
60