String.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. * This loader should only be used for unit testing as it has many limitations
  14. * (for instance, the include or extends tag does not make any sense for a string
  15. * loader).
  16. *
  17. * When using this loader with a cache mechanism, you should know that a new cache
  18. * key is generated each time a template content "changes" (the cache key being the
  19. * source code of the template). If you don't want to see your cache grows out of
  20. * control, you need to take care of clearing the old cache file by yourself.
  21. *
  22. * @package twig
  23. * @author Fabien Potencier <fabien@symfony.com>
  24. */
  25. class Twig_Loader_String implements Twig_LoaderInterface
  26. {
  27. /**
  28. * Gets the source code of a template, given its name.
  29. *
  30. * @param string $name The name of the template to load
  31. *
  32. * @return string The template source code
  33. */
  34. public function getSource($name)
  35. {
  36. return $name;
  37. }
  38. /**
  39. * Gets the cache key to use for the cache for a given template name.
  40. *
  41. * @param string $name The name of the template to load
  42. *
  43. * @return string The cache key
  44. */
  45. public function getCacheKey($name)
  46. {
  47. return $name;
  48. }
  49. /**
  50. * Returns true if the template is still fresh.
  51. *
  52. * @param string $name The template name
  53. * @param timestamp $time The last modification time of the cached template
  54. */
  55. public function isFresh($name, $time)
  56. {
  57. return true;
  58. }
  59. }