| 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 | 3 | public function setAttributes($attributes) |
|
| 28 | { |
||
| 29 | 3 | $this->attributes = $attributes; |
|
| 30 | |||
| 31 | 3 | 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 | 3 | public function render($view) |
|
| 54 | { |
||
| 55 | 3 | extract($this->attributes); |
|
| 56 | |||
| 57 | 3 | ob_start(); |
|
| 58 | 3 | require $view; |
|
| 59 | |||
| 60 | 3 | return $this->minify === true |
|
| 61 | 2 | ? $this->min(ob_get_clean()) |
|
| 62 | 3 | : 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 | 2 | protected function min($buffer) |
|
| 82 | } |
||
| 83 |