Passed
Push — master ( 3f508b...939a62 )
by El
05:26
created

View   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assign() 0 3 1
A draw() 0 9 3
1
<?php
2
/**
3
 * PrivateBin
4
 *
5
 * a zero-knowledge paste bin
6
 *
7
 * @link      https://github.com/PrivateBin/PrivateBin
8
 * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
9
 * @license   http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
10
 * @version   1.1.1
11
 */
12
13
namespace PrivateBin;
14
15
use Exception;
16
17
/**
18
 * View
19
 *
20
 * Displays the templates
21
 */
22
class View
23
{
24
    /**
25
     * variables available in the template
26
     *
27
     * @access private
28
     * @var    array
29
     */
30
    private $_variables = array();
31
32
    /**
33
     * assign variables to be used inside of the template
34
     *
35
     * @access public
36
     * @param  string $name
37
     * @param  mixed  $value
38
     */
39 38
    public function assign($name, $value)
40
    {
41 38
        $this->_variables[$name] = $value;
42 38
    }
43
44
    /**
45
     * render a template
46
     *
47
     * @access public
48
     * @param  string $template
49
     * @throws Exception
50
     */
51 38
    public function draw($template)
52
    {
53 38
        $file = substr($template, 0, 9) === 'bootstrap' ? 'bootstrap' : $template;
54 38
        $path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php';
55 38
        if (!file_exists($path)) {
56 1
            throw new Exception('Template ' . $template . ' not found!', 80);
57
        }
58 38
        extract($this->_variables);
59 38
        include $path;
60 38
    }
61
}
62