FileResource.php 981B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 OpenSky Project Inc
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Assetic\Factory\Resource;
  11. /**
  12. * A resource is something formulae can be loaded from.
  13. *
  14. * @author Kris Wallsmith <kris.wallsmith@gmail.com>
  15. */
  16. class FileResource implements ResourceInterface
  17. {
  18. private $path;
  19. /**
  20. * Constructor.
  21. *
  22. * @param string $path The path to a file
  23. */
  24. public function __construct($path)
  25. {
  26. $this->path = $path;
  27. }
  28. public function isFresh($timestamp)
  29. {
  30. return file_exists($this->path) && filemtime($this->path) <= $timestamp;
  31. }
  32. public function getContent()
  33. {
  34. return file_exists($this->path) ? file_get_contents($this->path) : '';
  35. }
  36. public function __toString()
  37. {
  38. return $this->path;
  39. }
  40. }