Template   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 74
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setTitle() 0 3 1
A setTemplate() 0 3 1
A set() 0 3 1
A get() 0 3 2
A render() 0 12 2
1
<?php
2
3
/**
4
 * Template
5
 * Clase para renderizar vistas dentro de una plantilla
6
 * @author nelson rojas
7
 */
8
class Template 
9
{
10
	/**
11
	 * @var string
12
	 */
13
	private $_template = 'default';
14
15
	/**
16
	 * @var string
17
	 */
18
	private $_title = '';
19
20
	/**
21
	 * @var array
22
	 */
23
	private $_properties = [];
24
25
	/**
26
	 * Método para setear propiedades
27
	 * @param string $prop
28
	 * @param mixed $value
29
	 */
30
	public function set($prop, $value)
31
	{
32
		$this->_properties[$prop] = $value;
33
	}
34
35
36
	/**
37
	 * Método para obtener propiedades
38
	 * @param string $prop
39
	 * @return mixed|null
40
	 */
41
	public function get($prop)
42
	{
43
		return isset($this->_properties[$prop]) ? $this->_properties[$prop] : null;
44
	}
45
46
	/**
47
	 * Permite asignar el template manualmente
48
	 * @param string $template
49
	 */
50
	public function setTemplate($template)
51
	{
52
		$this->_template = $template;
53
	}
54
55
	/**
56
	 * Permite asignar el title manualmente
57
	 * @param string $title
58
	 */
59
	public function setTitle($title)
60
	{
61
		$this->_title = $title;
62
	}
63
64
65
66
	/**
67
	 * Permite renderizar una vista dentro de la plantilla
68
	 * @param string $view
69
	 */
70
	public function render($view)
71
	{
72
		$template_file = PIN_PATH . 'templates' . DS . $this->_template . '.phtml';
73
		
74
		ob_start();
75
		load_view($view, $this->_properties);
76
		$yield = ob_get_clean();
77
		if (file_exists($template_file)) {
78
			$title = $this->_title;
79
			include $template_file;
80
		} else {
81
			throw new Exception("Archivo de template no encontrado $template_file", 1);
82
		}
83
	}
84
}