Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
View | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
assign | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
draw | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
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 https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License |
10 | * @version 1.7.2 |
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 | public function assign($name, $value) |
40 | { |
41 | $this->_variables[$name] = $value; |
42 | } |
43 | |
44 | /** |
45 | * render a template |
46 | * |
47 | * @access public |
48 | * @param string $template |
49 | * @throws Exception |
50 | */ |
51 | public function draw($template) |
52 | { |
53 | $file = substr($template, 0, 10) === 'bootstrap-' ? 'bootstrap' : $template; |
54 | $path = PATH . 'tpl' . DIRECTORY_SEPARATOR . $file . '.php'; |
55 | if (!file_exists($path)) { |
56 | throw new Exception('Template ' . $template . ' not found!', 80); |
57 | } |
58 | extract($this->_variables); |
59 | include $path; |
60 | } |
61 | } |