PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/#/vendor/smarty/sysplugins/smarty_internal_resource_file.php

https://bitbucket.org/nemo_xiaolan/muyou
PHP | 90 lines | 41 code | 9 blank | 40 comment | 7 complexity | e19b25703f5209ad1c094fa21d0b71e4 MD5 | raw file
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Resource File
  4. *
  5. * @package Smarty
  6. * @subpackage TemplateResources
  7. * @author Uwe Tews
  8. * @author Rodney Rehm
  9. */
  10. /**
  11. * Smarty Internal Plugin Resource File
  12. *
  13. * Implements the file system as resource for Smarty templates
  14. *
  15. * @package Smarty
  16. * @subpackage TemplateResources
  17. */
  18. class Smarty_Internal_Resource_File extends Smarty_Resource {
  19. /**
  20. * populate Source Object with meta data from Resource
  21. *
  22. * @param Smarty_Template_Source $source source object
  23. * @param Smarty_Internal_Template $_template template object
  24. */
  25. public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
  26. {
  27. $source->filepath = $this->buildFilepath($source, $_template);
  28. if ($source->filepath !== false) {
  29. if (is_object($source->smarty->security_policy)) {
  30. $source->smarty->security_policy->isTrustedResourceDir($source->filepath);
  31. }
  32. $source->uid = sha1($source->filepath);
  33. if ($source->smarty->compile_check && !isset($source->timestamp)) {
  34. $source->timestamp = @filemtime($source->filepath);
  35. $source->exists = !!$source->timestamp;
  36. }
  37. }
  38. }
  39. /**
  40. * populate Source Object with timestamp and exists from Resource
  41. *
  42. * @param Smarty_Template_Source $source source object
  43. */
  44. public function populateTimestamp(Smarty_Template_Source $source)
  45. {
  46. $source->timestamp = @filemtime($source->filepath);
  47. $source->exists = !!$source->timestamp;
  48. }
  49. /**
  50. * Load template's source from file into current template object
  51. *
  52. * @param Smarty_Template_Source $source source object
  53. * @return string template source
  54. * @throws SmartyException if source cannot be loaded
  55. */
  56. public function getContent(Smarty_Template_Source $source)
  57. {
  58. if ($source->timestamp) {
  59. return file_get_contents($source->filepath);
  60. }
  61. if ($source instanceof Smarty_Config_Source) {
  62. throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
  63. }
  64. throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
  65. }
  66. /**
  67. * Determine basename for compiled filename
  68. *
  69. * @param Smarty_Template_Source $source source object
  70. * @return string resource's basename
  71. */
  72. public function getBasename(Smarty_Template_Source $source)
  73. {
  74. $_file = $source->name;
  75. if (($_pos = strpos($_file, ']')) !== false) {
  76. $_file = substr($_file, $_pos + 1);
  77. }
  78. return basename($_file);
  79. }
  80. }
  81. ?>