FilesystemSpy.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. namespace League\Flysystem\Stub;
  3. use InvalidArgumentException;
  4. use League\Flysystem\FileExistsException;
  5. use League\Flysystem\FileNotFoundException;
  6. use League\Flysystem\FilesystemInterface;
  7. use League\Flysystem\Handler;
  8. use League\Flysystem\Plugin\PluggableTrait;
  9. use League\Flysystem\RootViolationException;
  10. class FilesystemSpy implements FilesystemInterface
  11. {
  12. use PluggableTrait;
  13. public $lastCall = [];
  14. /**
  15. * Check whether a file exists.
  16. *
  17. * @param string $path
  18. *
  19. * @return bool
  20. */
  21. public function has($path)
  22. {
  23. $this->lastCall = [__METHOD__, func_get_args()];
  24. }
  25. /**
  26. * Read a file.
  27. *
  28. * @param string $path The path to the file.
  29. *
  30. * @throws FileNotFoundException
  31. *
  32. * @return string|false The file contents or false on failure.
  33. */
  34. public function read($path)
  35. {
  36. $this->lastCall = [__METHOD__, func_get_args()];
  37. }
  38. /**
  39. * Retrieves a read-stream for a path.
  40. *
  41. * @param string $path The path to the file.
  42. *
  43. * @throws FileNotFoundException
  44. *
  45. * @return resource|false The path resource or false on failure.
  46. */
  47. public function readStream($path)
  48. {
  49. $this->lastCall = [__METHOD__, func_get_args()];
  50. }
  51. /**
  52. * List contents of a directory.
  53. *
  54. * @param string $directory The directory to list.
  55. * @param bool $recursive Whether to list recursively.
  56. *
  57. * @return array A list of file metadata.
  58. */
  59. public function listContents($directory = '', $recursive = false)
  60. {
  61. $this->lastCall = [__METHOD__, func_get_args()];
  62. }
  63. /**
  64. * Get a file's metadata.
  65. *
  66. * @param string $path The path to the file.
  67. *
  68. * @throws FileNotFoundException
  69. *
  70. * @return array|false The file metadata or false on failure.
  71. */
  72. public function getMetadata($path)
  73. {
  74. $this->lastCall = [__METHOD__, func_get_args()];
  75. }
  76. /**
  77. * Get a file's size.
  78. *
  79. * @param string $path The path to the file.
  80. *
  81. * @throws FileNotFoundException
  82. *
  83. * @return int|false The file size or false on failure.
  84. */
  85. public function getSize($path)
  86. {
  87. $this->lastCall = [__METHOD__, func_get_args()];
  88. }
  89. /**
  90. * Get a file's mime-type.
  91. *
  92. * @param string $path The path to the file.
  93. *
  94. * @throws FileNotFoundException
  95. *
  96. * @return string|false The file mime-type or false on failure.
  97. */
  98. public function getMimetype($path)
  99. {
  100. $this->lastCall = [__METHOD__, func_get_args()];
  101. }
  102. /**
  103. * Get a file's timestamp.
  104. *
  105. * @param string $path The path to the file.
  106. *
  107. * @throws FileNotFoundException
  108. *
  109. * @return string|false The timestamp or false on failure.
  110. */
  111. public function getTimestamp($path)
  112. {
  113. $this->lastCall = [__METHOD__, func_get_args()];
  114. }
  115. /**
  116. * Get a file's visibility.
  117. *
  118. * @param string $path The path to the file.
  119. *
  120. * @throws FileNotFoundException
  121. *
  122. * @return string|false The visibility (public|private) or false on failure.
  123. */
  124. public function getVisibility($path)
  125. {
  126. $this->lastCall = [__METHOD__, func_get_args()];
  127. }
  128. /**
  129. * Write a new file.
  130. *
  131. * @param string $path The path of the new file.
  132. * @param string $contents The file contents.
  133. * @param array $config An optional configuration array.
  134. *
  135. * @throws FileExistsException
  136. *
  137. * @return bool True on success, false on failure.
  138. */
  139. public function write($path, $contents, array $config = [])
  140. {
  141. $this->lastCall = [__METHOD__, func_get_args()];
  142. }
  143. /**
  144. * Write a new file using a stream.
  145. *
  146. * @param string $path The path of the new file.
  147. * @param resource $resource The file handle.
  148. * @param array $config An optional configuration array.
  149. *
  150. * @throws InvalidArgumentException If $resource is not a file handle.
  151. * @throws FileExistsException
  152. *
  153. * @return bool True on success, false on failure.
  154. */
  155. public function writeStream($path, $resource, array $config = [])
  156. {
  157. $this->lastCall = [__METHOD__, func_get_args()];
  158. }
  159. /**
  160. * Update an existing file.
  161. *
  162. * @param string $path The path of the existing file.
  163. * @param string $contents The file contents.
  164. * @param array $config An optional configuration array.
  165. *
  166. * @throws FileNotFoundException
  167. *
  168. * @return bool True on success, false on failure.
  169. */
  170. public function update($path, $contents, array $config = [])
  171. {
  172. $this->lastCall = [__METHOD__, func_get_args()];
  173. }
  174. /**
  175. * Update an existing file using a stream.
  176. *
  177. * @param string $path The path of the existing file.
  178. * @param resource $resource The file handle.
  179. * @param array $config An optional configuration array.
  180. *
  181. * @throws InvalidArgumentException If $resource is not a file handle.
  182. * @throws FileNotFoundException
  183. *
  184. * @return bool True on success, false on failure.
  185. */
  186. public function updateStream($path, $resource, array $config = [])
  187. {
  188. $this->lastCall = [__METHOD__, func_get_args()];
  189. }
  190. /**
  191. * Rename a file.
  192. *
  193. * @param string $path Path to the existing file.
  194. * @param string $newpath The new path of the file.
  195. *
  196. * @throws FileExistsException Thrown if $newpath exists.
  197. * @throws FileNotFoundException Thrown if $path does not exist.
  198. *
  199. * @return bool True on success, false on failure.
  200. */
  201. public function rename($path, $newpath)
  202. {
  203. $this->lastCall = [__METHOD__, func_get_args()];
  204. }
  205. /**
  206. * Copy a file.
  207. *
  208. * @param string $path Path to the existing file.
  209. * @param string $newpath The new path of the file.
  210. *
  211. * @throws FileExistsException Thrown if $newpath exists.
  212. * @throws FileNotFoundException Thrown if $path does not exist.
  213. *
  214. * @return bool True on success, false on failure.
  215. */
  216. public function copy($path, $newpath)
  217. {
  218. $this->lastCall = [__METHOD__, func_get_args()];
  219. }
  220. /**
  221. * Delete a file.
  222. *
  223. * @param string $path
  224. *
  225. * @throws FileNotFoundException
  226. *
  227. * @return bool True on success, false on failure.
  228. */
  229. public function delete($path)
  230. {
  231. $this->lastCall = [__METHOD__, func_get_args()];
  232. }
  233. /**
  234. * Delete a directory.
  235. *
  236. * @param string $dirname
  237. *
  238. * @throws RootViolationException Thrown if $dirname is empty.
  239. *
  240. * @return bool True on success, false on failure.
  241. */
  242. public function deleteDir($dirname)
  243. {
  244. $this->lastCall = [__METHOD__, func_get_args()];
  245. }
  246. /**
  247. * Create a directory.
  248. *
  249. * @param string $dirname The name of the new directory.
  250. * @param array $config An optional configuration array.
  251. *
  252. * @return bool True on success, false on failure.
  253. */
  254. public function createDir($dirname, array $config = [])
  255. {
  256. $this->lastCall = [__METHOD__, func_get_args()];
  257. }
  258. /**
  259. * Set the visibility for a file.
  260. *
  261. * @param string $path The path to the file.
  262. * @param string $visibility One of 'public' or 'private'.
  263. *
  264. * @throws FileNotFoundException
  265. *
  266. * @return bool True on success, false on failure.
  267. */
  268. public function setVisibility($path, $visibility)
  269. {
  270. $this->lastCall = [__METHOD__, func_get_args()];
  271. }
  272. /**
  273. * Create a file or update if exists.
  274. *
  275. * @param string $path The path to the file.
  276. * @param string $contents The file contents.
  277. * @param array $config An optional configuration array.
  278. *
  279. * @return bool True on success, false on failure.
  280. */
  281. public function put($path, $contents, array $config = [])
  282. {
  283. $this->lastCall = [__METHOD__, func_get_args()];
  284. }
  285. /**
  286. * Create a file or update if exists.
  287. *
  288. * @param string $path The path to the file.
  289. * @param resource $resource The file handle.
  290. * @param array $config An optional configuration array.
  291. *
  292. * @throws InvalidArgumentException Thrown if $resource is not a resource.
  293. *
  294. * @return bool True on success, false on failure.
  295. */
  296. public function putStream($path, $resource, array $config = [])
  297. {
  298. $this->lastCall = [__METHOD__, func_get_args()];
  299. }
  300. /**
  301. * Read and delete a file.
  302. *
  303. * @param string $path The path to the file.
  304. *
  305. * @throws FileNotFoundException
  306. *
  307. * @return string|false The file contents, or false on failure.
  308. */
  309. public function readAndDelete($path)
  310. {
  311. $this->lastCall = [__METHOD__, func_get_args()];
  312. }
  313. /**
  314. * Get a file/directory handler.
  315. *
  316. * @deprecated
  317. *
  318. * @param string $path The path to the file.
  319. * @param Handler $handler An optional existing handler to populate.
  320. *
  321. * @return Handler Either a file or directory handler.
  322. */
  323. public function get($path, Handler $handler = null)
  324. {
  325. $this->lastCall = [__METHOD__, func_get_args()];
  326. }
  327. }