Passed
Branch v1.5.1 (4f5540)
by Wanderson
05:07
created

View::validateFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Win\Views;
4
5
use Win\Application;
6
use Win\Common\Template;
7
use Win\Response\Response;
8
use Win\Request\HttpException;
9
10
/**
11
 * View
12
 *
13
 * Responsável por criar o visual da página
14
 */
15
class View extends Template implements Response
16
{
17
	/**
18
	 * Cria uma View com base no arquivo escolhido
19
	 * @param string $file arquivo da View
20
	 */
21
	public function __construct($file)
22
	{
23
		Application::app()->view = $this;
24
		$controller = Application::app()->controller;
25
		$data = get_object_vars($controller);
26
		parent::__construct($file, $data, 'shared/' . $controller->layout);
27
		$this->validateFile();
28
	}
29
30
	private function validateFile()
31
	{
32
		if (!$this->exists()) {
33
			throw new HttpException("View '{$this->file}' not found", 404);
34
		}
35
	}
36
37
	/** @return string */
38
	public function getTitle()
39
	{
40
		return $this->getData('title');
41
	}
42
43
	/**
44
	 * Envia a resposta Html
45
	 * @return string
46
	 */
47
	public function respond()
48
	{
49
		return $this->toHtml();
50
	}
51
}
52