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

View   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 35
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getTitle() 0 3 1
A respond() 0 3 1
A validateFile() 0 4 2
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