smarty_internal_resource_registered.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource Registered
  4. *
  5. * @package Smarty
  6. * @subpackage TemplateResources
  7. * @author Uwe Tews
  8. * @author Rodney Rehm
  9. */
  10. /**
  11. * Smarty Internal Plugin Resource Registered
  12. *
  13. * Implements the registered resource for Smarty template
  14. *
  15. * @package Smarty
  16. * @subpackage TemplateResources
  17. * @deprecated
  18. */
  19. class Smarty_Internal_Resource_Registered extends Smarty_Resource {
  20. /**
  21. * populate Source Object with meta data from Resource
  22. *
  23. * @param Smarty_Template_Source $source source object
  24. * @param Smarty_Internal_Template $_template template object
  25. * @return void
  26. */
  27. public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
  28. {
  29. $source->filepath = $source->type . ':' . $source->name;
  30. $source->uid = sha1($source->filepath);
  31. if ($source->smarty->compile_check) {
  32. $source->timestamp = $this->getTemplateTimestamp($source);
  33. $source->exists = !!$source->timestamp;
  34. }
  35. }
  36. /**
  37. * populate Source Object with timestamp and exists from Resource
  38. *
  39. * @param Smarty_Template_Source $source source object
  40. * @return void
  41. */
  42. public function populateTimestamp(Smarty_Template_Source $source)
  43. {
  44. $source->timestamp = $this->getTemplateTimestamp($source);
  45. $source->exists = !!$source->timestamp;
  46. }
  47. /**
  48. * Get timestamp (epoch) the template source was modified
  49. *
  50. * @param Smarty_Template_Source $source source object
  51. * @return integer|boolean timestamp (epoch) the template was modified, false if resources has no timestamp
  52. */
  53. public function getTemplateTimestamp(Smarty_Template_Source $source)
  54. {
  55. // return timestamp
  56. $time_stamp = false;
  57. call_user_func_array($source->smarty->registered_resources[$source->type][0][1], array($source->name, &$time_stamp, $source->smarty));
  58. return is_numeric($time_stamp) ? (int) $time_stamp : $time_stamp;
  59. }
  60. /**
  61. * Load template's source by invoking the registered callback into current template object
  62. *
  63. * @param Smarty_Template_Source $source source object
  64. * @return string template source
  65. * @throws SmartyException if source cannot be loaded
  66. */
  67. public function getContent(Smarty_Template_Source $source)
  68. {
  69. // return template string
  70. $t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$source->content, $source->smarty));
  71. if (is_bool($t) && !$t) {
  72. throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
  73. }
  74. return $source->content;
  75. }
  76. /**
  77. * Determine basename for compiled filename
  78. *
  79. * @param Smarty_Template_Source $source source object
  80. * @return string resource's basename
  81. */
  82. protected function getBasename(Smarty_Template_Source $source)
  83. {
  84. return basename($source->name);
  85. }
  86. }
  87. ?>