File.php 4.1 KB

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