FileResource.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\Config\Resource;
  11. /**
  12. * FileResource represents a resource stored on the filesystem.
  13. *
  14. * The resource can be a file or a directory.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class FileResource implements ResourceInterface, \Serializable
  19. {
  20. private $resource;
  21. /**
  22. * Constructor.
  23. *
  24. * @param string $resource The file path to the resource
  25. */
  26. public function __construct($resource)
  27. {
  28. $this->resource = realpath($resource);
  29. }
  30. /**
  31. * Returns a string representation of the Resource.
  32. *
  33. * @return string A string representation of the Resource
  34. */
  35. public function __toString()
  36. {
  37. return (string) $this->resource;
  38. }
  39. /**
  40. * Returns the resource tied to this Resource.
  41. *
  42. * @return mixed The resource
  43. */
  44. public function getResource()
  45. {
  46. return $this->resource;
  47. }
  48. /**
  49. * Returns true if the resource has not been updated since the given timestamp.
  50. *
  51. * @param integer $timestamp The last time the resource was loaded
  52. *
  53. * @return Boolean true if the resource has not been updated, false otherwise
  54. */
  55. public function isFresh($timestamp)
  56. {
  57. if (!file_exists($this->resource)) {
  58. return false;
  59. }
  60. return filemtime($this->resource) < $timestamp;
  61. }
  62. public function serialize()
  63. {
  64. return serialize($this->resource);
  65. }
  66. public function unserialize($serialized)
  67. {
  68. $this->resource = unserialize($serialized);
  69. }
  70. }