PhpStorageInterface.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Drupal\Component\PhpStorage;
  3. /**
  4. * Stores and loads PHP code.
  5. *
  6. * Each interface function takes $name as a parameter. This is a virtual file
  7. * name: for example, 'foo.php' or 'some/relative/path/to/foo.php'. The
  8. * storage implementation may store these as files within the local file system,
  9. * use a remote stream, combine multiple virtual files into an archive, store
  10. * them in database records, or use some other storage technique.
  11. */
  12. interface PhpStorageInterface {
  13. /**
  14. * Checks whether the PHP code exists in storage.
  15. *
  16. * @param string $name
  17. * The virtual file name. Can be a relative path.
  18. *
  19. * @return bool
  20. * TRUE if the virtual file exists, FALSE otherwise.
  21. */
  22. public function exists($name);
  23. /**
  24. * Loads PHP code from storage.
  25. *
  26. * Depending on storage implementation, exists() checks can be expensive, so
  27. * this function may be called for a file that doesn't exist, and that should
  28. * not result in errors. This function does not return anything, so it is
  29. * up to the caller to determine if any code was loaded (for example, check
  30. * class_exists() or function_exists() for what was expected in the code).
  31. *
  32. * @param string $name
  33. * The virtual file name. Can be a relative path.
  34. */
  35. public function load($name);
  36. /**
  37. * Saves PHP code to storage.
  38. *
  39. * @param string $name
  40. * The virtual file name. Can be a relative path.
  41. * @param string $code
  42. * The PHP code to be saved.
  43. *
  44. * @return bool
  45. * TRUE if the save succeeded, FALSE if it failed.
  46. */
  47. public function save($name, $code);
  48. /**
  49. * Whether this is a writable storage.
  50. *
  51. * @return bool
  52. */
  53. public function writeable();
  54. /**
  55. * Deletes PHP code from storage.
  56. *
  57. * @param string $name
  58. * The virtual file name. Can be a relative path.
  59. *
  60. * @return bool
  61. * TRUE if the delete succeeded, FALSE if it failed.
  62. */
  63. public function delete($name);
  64. /**
  65. * Removes all files in this bin.
  66. */
  67. public function deleteAll();
  68. /**
  69. * Gets the full file path.
  70. *
  71. * @param string $name
  72. * The virtual file name. Can be a relative path.
  73. *
  74. * @return string|false
  75. * The full file path for the provided name. Return FALSE if the
  76. * implementation needs to prevent access to the file.
  77. */
  78. public function getFullPath($name);
  79. /**
  80. * Lists all the files in the storage.
  81. *
  82. * @return array
  83. * Array of filenames.
  84. */
  85. public function listAll();
  86. /**
  87. * Performs garbage collection on the storage.
  88. *
  89. * The storage may choose to delete expired or invalidated items.
  90. */
  91. public function garbageCollection();
  92. }