Passed
Branch v1.5.1 (9f4477)
by Wanderson
01:49
created

View::respond()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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