| Total Complexity | 11 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | trait view { |
||
| 15 | private $template = ''; |
||
| 16 | protected $vars = []; |
||
| 17 | protected $component = ''; |
||
| 18 | |||
| 19 | public function __construct($path) { |
||
| 20 | $view_name = explode('\\', get_class($this))[count(explode('\\', get_class($this)))-1]; |
||
| 21 | if(is_file("{$path}/src/{$view_name}.view.html")) { |
||
| 22 | $this->template = file_get_contents("{$path}/src/{$view_name}.view.html"); |
||
| 23 | } |
||
| 24 | } |
||
| 25 | |||
| 26 | public function set_parent($parent_class) { |
||
| 27 | if(strstr(__CLASS__, 'custom')) { |
||
| 28 | $this->set_vars(['parent' => $parent_class->get_template()]); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | public function set_vars($vars) { |
||
| 33 | foreach ($vars as $var => $value) { |
||
| 34 | $this->vars[$var] = $value; |
||
| 35 | } |
||
| 36 | return $this; |
||
| 37 | } |
||
| 38 | |||
| 39 | public function get_template():string { |
||
| 40 | return $this->template; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function before_render() {} |
||
| 44 | |||
| 45 | protected function render_end(&$template) { |
||
| 46 | xphp::parse_template_content($template); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function render():string { |
||
| 57 | } |
||
| 58 | } |