smarty_resource_uncompiled.php (1889B)
1 <?php 2 /** 3 * Smarty Resource Plugin 4 * 5 * @package Smarty 6 * @subpackage TemplateResources 7 * @author Rodney Rehm 8 */ 9 10 /** 11 * Smarty Resource Plugin 12 * Base implementation for resource plugins that don't use the compiler 13 * 14 * @package Smarty 15 * @subpackage TemplateResources 16 */ 17 abstract class Smarty_Resource_Uncompiled extends Smarty_Resource 18 { 19 /** 20 * Flag that it's an uncompiled resource 21 * 22 * @var bool 23 */ 24 public $uncompiled = true; 25 26 /** 27 * Render and output the template (without using the compiler) 28 * 29 * @param Smarty_Template_Source $source source object 30 * @param Smarty_Internal_Template $_template template object 31 * 32 * @throws SmartyException on failure 33 */ 34 abstract public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template); 35 36 /** 37 * populate compiled object with compiled filepath 38 * 39 * @param Smarty_Template_Compiled $compiled compiled object 40 * @param Smarty_Internal_Template $_template template object (is ignored) 41 */ 42 public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) 43 { 44 $compiled->filepath = false; 45 $compiled->timestamp = false; 46 $compiled->exists = false; 47 } 48 49 /** 50 * render compiled template code 51 * 52 * @param Smarty_Internal_Template $_template 53 * 54 * @return string 55 * @throws Exception 56 */ 57 public function render($_template) 58 { 59 $level = ob_get_level(); 60 ob_start(); 61 try { 62 $this->renderUncompiled($_template->source, $_template); 63 return ob_get_clean(); 64 } 65 catch (Exception $e) { 66 while (ob_get_level() > $level) { 67 ob_end_clean(); 68 } 69 throw $e; 70 } 71 } 72 }