* @package taoItems */ class taoItems_models_classes_TemplateRenderer { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- /** * Short description of attribute context * * @access protected * @var array */ protected static $context = []; /** * ClearFW Renderer * * @access private */ private $renderer = null; // --- OPERATIONS --- /** * Short description of method __construct * * @access public * @author Joel Bout, * @param string templatePath * @param array variables * @return mixed */ public function __construct($templatePath, $variables = []) { if ( !file_exists($templatePath) || !is_readable($templatePath) || !preg_match("/\.tpl\.php$/", basename($templatePath)) ) { common_Logger::w('Template ', $templatePath . ' not found'); throw new InvalidArgumentException("Unable to load the template file from $templatePath"); } if (!tao_helpers_File::securityCheck($templatePath)) { throw new Exception("Security warning: $templatePath is not safe."); } $this->renderer = new Renderer($templatePath, $variables); } /** * Short description of method setContext * * @access public * @author Joel Bout, * @param array parameters * @param string prefix * @return mixed */ public static function setContext($parameters, $prefix = '') { self::$context = []; foreach ($parameters as $key => $value) { self::$context[$prefix . $key] = $value; } } /** * sets the template to be used * * @access public * @author Joel Bout, * @param string templatePath * @return mixed */ public function setTemplate($templatePath) { $this->renderer->setTemplate($templatePath); } /** * adds or replaces the data for a specific key * * @access public * @author Joel Bout, * @param string key * @param value * @return mixed */ public function setData($key, $value) { $this->renderer->setData($key, $value); } /** * Short description of method render * * @access public * @author Joel Bout, * @return string */ public function render() { $returnValue = (string) ''; $this->renderer->setMultipleData(self::$context); $returnValue = $this->renderer->render(); return (string) $returnValue; } }