Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2775 rexy 1
<?php
2
/**
3
 * basic output functions
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Output
9
 * @author    Damien Roth <iysaak@users.sourceforge.net>
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
12
 * @version   SVN: $Id: class.Output.inc.php 315 2009-09-02 15:48:31Z bigmichi1 $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
/**
16
 * basic output functions for all output formats
17
 *
18
 * @category  PHP
19
 * @package   PSI_Output
20
 * @author    Damien Roth <iysaak@users.sourceforge.net>
21
 * @copyright 2009 phpSysInfo
22
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
23
 * @version   Release: 3.0
24
 * @link      http://phpsysinfo.sourceforge.net
25
 */
26
class Template
27
{
28
    /**
29
     * Vars used in the template
30
     *
31
     * @var array
32
     */
33
    private $_vars;
34
 
35
    /**
36
     * Template file
37
     *
38
     * @var string
39
     */
40
    private $_file;
41
 
42
    /**
43
     * Constructor
44
     *
45
     * @param String $file the template file name
46
     */
47
    public function __construct($file=null)
48
    {
49
        $this->_file = $file;
50
        $this->_vars = array();
51
    }
52
 
53
    /**
54
     * Set a template variable.
55
     *
56
     * @param string                $name  variable name
57
     * @param string|array|Template $value variable value
58
     */
59
    public function set($name, $value)
60
    {
61
        $this->_vars[$name] = is_object($value) ? $value->fetch() : $value;
62
    }
63
 
64
    /**
65
     * Open, parse, and return the template file.
66
     *
67
     * @param string $file
68
     *
69
     * @return string
70
     */
71
    public function fetch($file=null)
72
    {
73
        if (!$file) {
74
            $file = $this->_file;
75
        }
76
 
77
        // Extract the vars to local namespace
78
        extract($this->_vars);
79
 
80
        // Start output buffering
81
        ob_start();
82
 
83
        include(PSI_APP_ROOT.$file);
84
 
85
        // Get the contents of the buffer
86
        $contents = ob_get_contents();
87
 
88
        // End buffering and discard
89
        ob_end_clean();
90
 
91
        return $contents;
92
    }
93
}