<?php

/* + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
 +                                                                   +
 * SmartTemplate                                                     *
 +                                                                   +
 * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */

require_once('HTML/Template/smarttemplate/class.smarttemplate.php');

/**
 * Implementation of the interface for SmartTemplate
 *
 * @package SmartTemplateInterfaced
 * @link http://www.smartphp.net
 **/
class SmartTemplateInterfaced extends TemplateInterfaced implements Template_Interface
{
    
/**
     * Class constructor
     **/
    
function __construct($options = array())
    {
        
$this->_templateReference null;
        
$this->_templateData = array();

        
// Filter only valid options
        
extract($optionsEXTR_SKIP);
        
$this->_templateOptions compact('temp_dir''cache_dir',
            
'cache_lifetime''template_dir''use_cache');
    }

    
/**
     * Open the template to be used.
     *
     * @access public
     * @param  string $template A template file name
     * @return mixed  TRUE or a PEAR_Error object on error
     **/
    
public function openTemplate($template)
    {
        
$this->_templateReference = new SmartTemplate($template);
        
// Set template engine's options
        
foreach ($this->_templateOptions as $name => $value) {
            if (
$name == 'use_cache') {
                
$this->_templateReference->use_cache();
            } else {
                
$this->_templateReference->{$name} = $value;
            }
        }
        return 
true;
    }

    
/**
     * Output the result of the template
     *
     * @access public
     * @return mixed TRUE or PEAR_Error on error
     **/
    
public function output()
    {
        if (
is_null($this->_templateReference)) {
            return 
PEAR::raiseError('You must call openTemplate() first.');
        }
        
$this->_templateReference->assign($this->_templateData);
        
$this->_templateReference->ouput();
        return 
true;
    }

    
/**
     * Return the result of the template as a string
     *
     * @access public
     * @return string
     **/
    
public function toString()
    {
        if (
is_null($this->_templateReference)) {
            return 
PEAR::raiseError('You must call openTemplate() first.');
        }
        
$this->_templateReference->assign($this->_templateData);
        return 
$this->_templateReference->result();
    }

// End [CLASS] SmartTemplateInterfaced


?>