String.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2009 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. /**
  11. * Loads a template from a string.
  12. *
  13. * When using this loader with a cache mechanism, you should know that a new cache
  14. * key is generated each time a template content "changes" (the cache key being the
  15. * source code of the template). If you don't want to see your cache grows out of
  16. * control, you need to take care of clearing the old cache file by yourself.
  17. *
  18. * @package twig
  19. * @author Fabien Potencier <fabien@symfony.com>
  20. */
  21. class Twig_Loader_String implements Twig_LoaderInterface
  22. {
  23. /**
  24. * Gets the source code of a template, given its name.
  25. *
  26. * @param string $name The name of the template to load
  27. *
  28. * @return string The template source code
  29. */
  30. public function getSource($name)
  31. {
  32. return $name;
  33. }
  34. /**
  35. * Gets the cache key to use for the cache for a given template name.
  36. *
  37. * @param string $name The name of the template to load
  38. *
  39. * @return string The cache key
  40. */
  41. public function getCacheKey($name)
  42. {
  43. return $name;
  44. }
  45. /**
  46. * Returns true if the template is still fresh.
  47. *
  48. * @param string $name The template name
  49. * @param timestamp $time The last modification time of the cached template
  50. */
  51. public function isFresh($name, $time)
  52. {
  53. return true;
  54. }
  55. }