Directory.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Elgg\Filesystem;
  3. /**
  4. * A simple directory abstraction.
  5. *
  6. * @since 1.10.2
  7. *
  8. * @access private
  9. */
  10. interface Directory {
  11. /**
  12. * Returns a subdirectory with access limited to the given directory.
  13. *
  14. * @param string $path The path relative to this directory to chroot to.
  15. *
  16. * @return Directory A new directory instance.
  17. */
  18. public function chroot($path);
  19. /**
  20. * Read the file off the filesystem.
  21. *
  22. * @param string $path The directory-relative path to the target file.
  23. *
  24. * @return string Empty string if the file doesn't exist.
  25. */
  26. public function getContents($path);
  27. /**
  28. * A reference to the file at the given path, even if it doesn't exist yet.
  29. *
  30. * However, will throw an exception if the file is already a directory.
  31. *
  32. * @param string $path The path to the file, relative to this directory.
  33. *
  34. * @return File
  35. */
  36. public function getFile($path);
  37. /**
  38. * Recursively list the files in the given directory path.
  39. *
  40. * @param string $path The subdirectory path within this directory
  41. *
  42. * @return Collection<File>
  43. */
  44. public function getFiles($path = '');
  45. /**
  46. * Do a PHP include of the file and return the result.
  47. *
  48. * NB: This only really works with local filesystems amirite?
  49. *
  50. * @param string $path Filesystem-relative path for the file to include.
  51. *
  52. * @return mixed
  53. */
  54. public function includeFile($path);
  55. /**
  56. * Whether this directory has an existing file at the given location.
  57. *
  58. * @param string $path The relative path within this directory
  59. *
  60. * @return boolean
  61. */
  62. public function isFile($path);
  63. /**
  64. * Write a file, overwriting the contents if necessary.
  65. *
  66. * @param string $path The path to the file.
  67. * @param string $content The literal text content of the file.
  68. *
  69. * @return void
  70. */
  71. public function putContents($path, $content);
  72. }