| Total Complexity | 9 |
| Total Lines | 87 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class Template |
||
| 12 | { |
||
| 13 | public static $dir = 'app/templates'; |
||
| 14 | /** |
||
| 15 | * Ponteiro para Aplicação Principal |
||
| 16 | * @var Application |
||
| 17 | */ |
||
| 18 | public $app; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Endereço completo do arquivo .phtml |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $file; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Variáveis para serem usadas no corpo do arquivo |
||
| 28 | * @var mixed[] |
||
| 29 | */ |
||
| 30 | protected $data = []; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Layout |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | private $layout = null; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Cria um template com base no arquivo escolhido |
||
| 40 | * @param string $file Nome do arquivo |
||
| 41 | * @param mixed[] $data Array de variáveis |
||
| 42 | * @param string $layout Layout |
||
| 43 | */ |
||
| 44 | public function __construct($file, $data = [], $layout = null) |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Retorna uma variável |
||
| 54 | * @param string $name |
||
| 55 | * @return mixed|null |
||
| 56 | */ |
||
| 57 | public function getData($name) |
||
| 58 | { |
||
| 59 | if (key_exists($name, $this->data)) { |
||
| 60 | return $this->data[$name]; |
||
| 61 | } |
||
| 62 | |||
| 63 | return null; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Retorna TRUE se o template existe |
||
| 68 | * @return bool |
||
| 69 | */ |
||
| 70 | public function exists() |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Carrega e retorna o output |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | public function toHtml() |
||
| 80 | { |
||
| 81 | if ($this->layout) { |
||
| 82 | return (new Layout($this->layout, $this))->toHtml(); |
||
| 83 | } |
||
| 84 | |||
| 85 | ob_start(); |
||
| 86 | $this->load(); |
||
| 87 | return ob_get_clean(); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Carrega e exibe o conteúdo do template |
||
| 92 | */ |
||
| 93 | public function load() |
||
| 98 | } |
||
| 99 | } |
||
| 101 |