ElggFilestore.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * This class defines the interface for all elgg data repositories.
  4. *
  5. * @package Elgg.Core
  6. * @subpackage DataStorage
  7. * @class \ElggFilestore
  8. */
  9. abstract class ElggFilestore {
  10. /**
  11. * Attempt to open the file $file for storage or writing.
  12. *
  13. * @param \ElggFile $file A file
  14. * @param string $mode "read", "write", "append"
  15. *
  16. * @return mixed A handle to the opened file or false on error.
  17. */
  18. abstract public function open(\ElggFile $file, $mode);
  19. /**
  20. * Write data to a given file handle.
  21. *
  22. * @param mixed $f The file handle - exactly what this is depends on the file system
  23. * @param string $data The binary string of data to write
  24. *
  25. * @return int Number of bytes written.
  26. */
  27. abstract public function write($f, $data);
  28. /**
  29. * Read data from a filestore.
  30. *
  31. * @param mixed $f The file handle
  32. * @param int $length Length in bytes to read.
  33. * @param int $offset The optional offset.
  34. *
  35. * @return mixed String of data or false on error.
  36. */
  37. abstract public function read($f, $length, $offset = 0);
  38. /**
  39. * Seek a given position within a file handle.
  40. *
  41. * @param mixed $f The file handle.
  42. * @param int $position The position.
  43. *
  44. * @return void
  45. */
  46. abstract public function seek($f, $position);
  47. /**
  48. * Return a whether the end of a file has been reached.
  49. *
  50. * @param mixed $f The file handle.
  51. *
  52. * @return boolean
  53. */
  54. abstract public function eof($f);
  55. /**
  56. * Return the current position in an open file.
  57. *
  58. * @param mixed $f The file handle.
  59. *
  60. * @return int
  61. */
  62. abstract public function tell($f);
  63. /**
  64. * Close a given file handle.
  65. *
  66. * @param mixed $f The file handle
  67. *
  68. * @return bool
  69. */
  70. abstract public function close($f);
  71. /**
  72. * Delete the file associated with a given file handle.
  73. *
  74. * @param \ElggFile $file The file
  75. *
  76. * @return bool
  77. */
  78. abstract public function delete(\ElggFile $file);
  79. /**
  80. * Return the size in bytes for a given file.
  81. *
  82. * @param \ElggFile $file The file
  83. *
  84. * @return int
  85. */
  86. abstract public function getFileSize(\ElggFile $file);
  87. /**
  88. * Return the filename of a given file as stored on the filestore.
  89. *
  90. * @param \ElggFile $file The file
  91. *
  92. * @return string
  93. */
  94. abstract public function getFilenameOnFilestore(\ElggFile $file);
  95. /**
  96. * Get the filestore's creation parameters as an associative array.
  97. * Used for serialisation and for storing the creation details along side a file object.
  98. *
  99. * @return array
  100. */
  101. abstract public function getParameters();
  102. /**
  103. * Set the parameters from the associative array produced by $this->getParameters().
  104. *
  105. * @param array $parameters A list of parameters
  106. *
  107. * @return bool
  108. */
  109. abstract public function setParameters(array $parameters);
  110. /**
  111. * Get the contents of the whole file.
  112. *
  113. * @param mixed $file The file handle.
  114. *
  115. * @return mixed The file contents.
  116. */
  117. abstract public function grabFile(\ElggFile $file);
  118. /**
  119. * Return whether a file physically exists or not.
  120. *
  121. * @param \ElggFile $file The file
  122. *
  123. * @return bool
  124. */
  125. abstract public function exists(\ElggFile $file);
  126. }