Passed
Branch tests1.5 (af713c)
by Wanderson
01:19
created

View::getFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\Mvc;
4
5
use Win\Html\Seo\Title;
6
7
/**
8
 * Views
9
 *
10
 * São responsáveis por criar o visual da página
11
 */
12
class View extends Block {
13
14
	public static $dir = '/app/view';
15
16
	/**
17
	 * Cria uma View com base no arquivo escolhido
18
	 * @param string $file arquivo da View
19
	 * @param mixed[] $data Variáveis
20
	 */
21
	public function __construct($file, $data = []) {
22
		parent::__construct($file, $data);
23
	}
24
25
	/**
26
	 * Executa o ErrorPage caso a view não exista
27
	 * @throws HttpException
28
	 */
29
	public function validate() {
30
		if (!$this->exists()) {
31
			throw new HttpException(404);
32
		}
33
	}
34
35
	/**
36
	 * Adiciona um array de variáveis para usar na View
37
	 * @param mixed[] $data
38
	 */
39
	public function mergeData(array $data) {
40
		$this->data = array_merge($this->data, $data);
41
	}
42
43
	/** @return string */
44
	public function getTitle() {
45
		if (empty($this->getData('title'))) {
46
			$this->addData('title', Title::otimize(ucwords(str_replace('-', ' ', $this->app->getPage()))));
47
		}
48
		return $this->getData('title');
49
	}
50
51
}
52