No Description

File.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace League\Flysystem;
  3. class File extends Handler
  4. {
  5. /**
  6. * Check whether the file exists.
  7. *
  8. * @return bool
  9. */
  10. public function exists()
  11. {
  12. return $this->filesystem->has($this->path);
  13. }
  14. /**
  15. * Read the file.
  16. *
  17. * @return string file contents
  18. */
  19. public function read()
  20. {
  21. return $this->filesystem->read($this->path);
  22. }
  23. /**
  24. * Read the file as a stream.
  25. *
  26. * @return resource file stream
  27. */
  28. public function readStream()
  29. {
  30. return $this->filesystem->readStream($this->path);
  31. }
  32. /**
  33. * Write the new file.
  34. *
  35. * @param string $content
  36. *
  37. * @return bool success boolean
  38. */
  39. public function write($content)
  40. {
  41. return $this->filesystem->write($this->path, $content);
  42. }
  43. /**
  44. * Write the new file using a stream.
  45. *
  46. * @param resource $resource
  47. *
  48. * @return bool success boolean
  49. */
  50. public function writeStream($resource)
  51. {
  52. return $this->filesystem->writeStream($this->path, $resource);
  53. }
  54. /**
  55. * Update the file contents.
  56. *
  57. * @param string $content
  58. *
  59. * @return bool success boolean
  60. */
  61. public function update($content)
  62. {
  63. return $this->filesystem->update($this->path, $content);
  64. }
  65. /**
  66. * Update the file contents with a stream.
  67. *
  68. * @param resource $resource
  69. *
  70. * @return bool success boolean
  71. */
  72. public function updateStream($resource)
  73. {
  74. return $this->filesystem->updateStream($this->path, $resource);
  75. }
  76. /**
  77. * Create the file or update if exists.
  78. *
  79. * @param string $content
  80. *
  81. * @return bool success boolean
  82. */
  83. public function put($content)
  84. {
  85. return $this->filesystem->put($this->path, $content);
  86. }
  87. /**
  88. * Create the file or update if exists using a stream.
  89. *
  90. * @param resource $resource
  91. *
  92. * @return bool success boolean
  93. */
  94. public function putStream($resource)
  95. {
  96. return $this->filesystem->putStream($this->path, $resource);
  97. }
  98. /**
  99. * Rename the file.
  100. *
  101. * @param string $newpath
  102. *
  103. * @return bool success boolean
  104. */
  105. public function rename($newpath)
  106. {
  107. if ($this->filesystem->rename($this->path, $newpath)) {
  108. $this->path = $newpath;
  109. return true;
  110. }
  111. return false;
  112. }
  113. /**
  114. * Copy the file.
  115. *
  116. * @param string $newpath
  117. *
  118. * @return File|false new file or false
  119. */
  120. public function copy($newpath)
  121. {
  122. if ($this->filesystem->copy($this->path, $newpath)) {
  123. return new File($this->filesystem, $newpath);
  124. }
  125. return false;
  126. }
  127. /**
  128. * Get the file's timestamp.
  129. *
  130. * @return int unix timestamp
  131. */
  132. public function getTimestamp()
  133. {
  134. return $this->filesystem->getTimestamp($this->path);
  135. }
  136. /**
  137. * Get the file's mimetype.
  138. *
  139. * @return string mimetime
  140. */
  141. public function getMimetype()
  142. {
  143. return $this->filesystem->getMimetype($this->path);
  144. }
  145. /**
  146. * Get the file's visibility.
  147. *
  148. * @return string visibility
  149. */
  150. public function getVisibility()
  151. {
  152. return $this->filesystem->getVisibility($this->path);
  153. }
  154. /**
  155. * Get the file's metadata.
  156. *
  157. * @return array
  158. */
  159. public function getMetadata()
  160. {
  161. return $this->filesystem->getMetadata($this->path);
  162. }
  163. /**
  164. * Get the file size.
  165. *
  166. * @return int file size
  167. */
  168. public function getSize()
  169. {
  170. return $this->filesystem->getSize($this->path);
  171. }
  172. /**
  173. * Delete the file.
  174. *
  175. * @return bool success boolean
  176. */
  177. public function delete()
  178. {
  179. return $this->filesystem->delete($this->path);
  180. }
  181. }