1 | <?php |
||
5 | class Template |
||
6 | { |
||
7 | /** |
||
8 | * $attributes. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $attributes = []; |
||
13 | |||
14 | /** |
||
15 | * $minify. |
||
16 | * |
||
17 | * @var bool |
||
18 | */ |
||
19 | protected $minify = true; |
||
20 | |||
21 | /** |
||
22 | * setAttributes. |
||
23 | * |
||
24 | * @param array $attributes |
||
25 | * @return $this |
||
26 | */ |
||
27 | 2 | public function setAttributes($attributes) |
|
28 | { |
||
29 | 2 | $this->attributes = $attributes; |
|
30 | |||
31 | 2 | return $this; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * minify. |
||
36 | * |
||
37 | * @param bool $minify |
||
38 | * @return $this |
||
39 | */ |
||
40 | 2 | public function minify($minify) |
|
46 | |||
47 | /** |
||
48 | * render. |
||
49 | * |
||
50 | * @param string $view |
||
51 | * @return string |
||
52 | */ |
||
53 | 2 | public function render($view) |
|
54 | { |
||
55 | 2 | extract($this->attributes); |
|
56 | |||
57 | 2 | ob_start(); |
|
58 | 2 | require $view; |
|
59 | |||
60 | 2 | return $this->minify === true |
|
61 | 1 | ? $this->min(ob_get_clean()) |
|
62 | 2 | : ob_get_clean(); |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * min. |
||
67 | * |
||
68 | * if need min style and script, refrence |
||
69 | * https://gist.github.com/recca0120/5930842de4e0a43a48b8bf027ab058f9 |
||
70 | * |
||
71 | * @param string $buffer |
||
72 | * @return string |
||
73 | */ |
||
74 | 1 | protected function min($buffer) |
|
82 | } |
||
83 |