Passed
Branch scrutinizer (dafd44)
by Wanderson
01:40
created

Template::getTheme()   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\DesignPattern\Singleton;
6
use const BASE_PATH;
7
8
/**
9
 * Sistema de Templates
10
 *
11
 * Permite que a aplicação tenha múltiplos Templates e facilita a alteração entre os Templates.
12
 *
13
 * Quando uma View ou Block é chamado, primeiro o arquivo será buscando em "template/[nome-do-template]"
14
 * E caso o arquivo não exista, será buscado em "template/default"
15
 */
16
class Template {
17
18
	use Singleton;
19
20
	protected static $dir = 'app/template/';
21
	protected static $themeDefault = 'default';
22
23
	/**
24
	 * Nome do Tema atual
25
	 * @var string
26
	 */
27
	private static $theme = null;
28
29
	/**
30
	 * Define o nome do Tema atual (Antes de instanciar o Application)
31
	 *
32
	 * Após esta chamada, todos os Blocos e Views serão buscados "template/[$theme]"
33
	 * @param string $theme
34
	 */
35
	public function setTheme($theme) {
36
		self::$theme = $theme;
37
	}
38
39
	/**
40
	 * Retorna o nome do Tema atual
41
	 * @return string
42
	 */
43
	public function getTheme() {
44
		return self::$theme;
45
	}
46
47
	/**
48
	 * Retorna o Novo caminho completo do arquivo
49
	 * (incluindo o diretório do template atual)
50
	 * 
51
	 * @param string $dir diretório atual da View
52
	 * @param string $file Arquivo atual da View
53
	 * @return string Novo caminho completo da View
54
	 */
55
	public function getFilePath($dir, $file) {
56
		$appDir = BASE_PATH . '/app/';
57
		$newDir = str_replace($appDir, '', $dir);
58
		if (file_exists(self::$dir . self::$theme . '/' . $newDir . $file . '.phtml')) {
59
			return self::$dir . self::$theme . '/' . $newDir . $file;
60
		}
61
		return self::$dir . self::$themeDefault . '/' . $newDir . $file;
62
	}
63
64
}
65