You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_resource_uncompiled.php 2.0KB

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