DriverInterface.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <?php
  2. /**
  3. * Interface of Magento filesystem driver
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\Filesystem;
  9. use Magento\Framework\Exception\FileSystemException;
  10. /**
  11. * Class Driver
  12. *
  13. * @api
  14. * @since 100.0.2
  15. */
  16. interface DriverInterface
  17. {
  18. /**
  19. * Permissions to give read/write/execute access to owner and owning group, but not to all users
  20. *
  21. * @deprecated
  22. */
  23. const WRITEABLE_DIRECTORY_MODE = 0770;
  24. /**
  25. * Permissions to give read/write access to owner and owning group, but not to all users
  26. *
  27. * @deprecated
  28. */
  29. const WRITEABLE_FILE_MODE = 0660;
  30. /**
  31. *
  32. * @param string $path
  33. * @return bool
  34. * @throws FileSystemException
  35. */
  36. public function isExists($path);
  37. /**
  38. * Gathers the statistics of the given path
  39. *
  40. * @param string $path
  41. * @return array
  42. * @throws FileSystemException
  43. */
  44. public function stat($path);
  45. /**
  46. * Check permissions for reading file or directory
  47. *
  48. * @param string $path
  49. * @return bool
  50. * @throws FileSystemException
  51. */
  52. public function isReadable($path);
  53. /**
  54. * Tells whether the filename is a regular file
  55. *
  56. * @param string $path
  57. * @return bool
  58. * @throws FileSystemException
  59. */
  60. public function isFile($path);
  61. /**
  62. * Tells whether the filename is a regular directory
  63. *
  64. * @param string $path
  65. * @return bool
  66. * @throws FileSystemException
  67. */
  68. public function isDirectory($path);
  69. /**
  70. * Retrieve file contents from given path
  71. *
  72. * @param string $path
  73. * @param string|null $flag
  74. * @param resource|null $context
  75. * @return string
  76. * @throws FileSystemException
  77. */
  78. public function fileGetContents($path, $flag = null, $context = null);
  79. /**
  80. * Check if given path is writable
  81. *
  82. * @param string $path
  83. * @return bool
  84. * @throws FileSystemException
  85. */
  86. public function isWritable($path);
  87. /**
  88. * Returns parent directory's path
  89. *
  90. * @param string $path
  91. * @return string
  92. */
  93. public function getParentDirectory($path);
  94. /**
  95. * Create directory
  96. *
  97. * @param string $path
  98. * @param int $permissions
  99. * @return bool
  100. * @throws FileSystemException
  101. */
  102. public function createDirectory($path, $permissions = 0777);
  103. /**
  104. * Read directory
  105. *
  106. * @param string $path
  107. * @return array
  108. * @throws FileSystemException
  109. */
  110. public function readDirectory($path);
  111. /**
  112. * Read directory recursively
  113. *
  114. * @param string|null $path
  115. * @return array
  116. * @throws FileSystemException
  117. */
  118. public function readDirectoryRecursively($path = null);
  119. /**
  120. * Search paths by given regex
  121. *
  122. * @param string $pattern
  123. * @param string $path
  124. * @return array
  125. * @throws FileSystemException
  126. */
  127. public function search($pattern, $path);
  128. /**
  129. * Renames a file or directory
  130. *
  131. * @param string $oldPath
  132. * @param string $newPath
  133. * @param DriverInterface|null $targetDriver
  134. * @return bool
  135. * @throws FileSystemException
  136. */
  137. public function rename($oldPath, $newPath, DriverInterface $targetDriver = null);
  138. /**
  139. * Copy source into destination
  140. *
  141. * @param string $source
  142. * @param string $destination
  143. * @param DriverInterface|null $targetDriver
  144. * @return bool
  145. * @throws FileSystemException
  146. */
  147. public function copy($source, $destination, DriverInterface $targetDriver = null);
  148. /**
  149. * Create symlink on source and place it into destination
  150. *
  151. * @param string $source
  152. * @param string $destination
  153. * @param DriverInterface|null $targetDriver
  154. * @return bool
  155. * @throws FileSystemException
  156. */
  157. public function symlink($source, $destination, DriverInterface $targetDriver = null);
  158. /**
  159. * Delete file
  160. *
  161. * @param string $path
  162. * @return bool
  163. * @throws FileSystemException
  164. */
  165. public function deleteFile($path);
  166. /**
  167. * Delete directory
  168. *
  169. * @param string $path
  170. * @return bool
  171. * @throws FileSystemException
  172. */
  173. public function deleteDirectory($path);
  174. /**
  175. * Change permissions of given path
  176. *
  177. * @param string $path
  178. * @param int $permissions
  179. * @return bool
  180. * @throws FileSystemException
  181. */
  182. public function changePermissions($path, $permissions);
  183. /**
  184. * Recursively hange permissions of given path
  185. *
  186. * @param string $path
  187. * @param int $dirPermissions
  188. * @param int $filePermissions
  189. * @return bool
  190. * @throws FileSystemException
  191. */
  192. public function changePermissionsRecursively($path, $dirPermissions, $filePermissions);
  193. /**
  194. * Sets access and modification time of file.
  195. *
  196. * @param string $path
  197. * @param int|null $modificationTime
  198. * @return bool
  199. * @throws FileSystemException
  200. */
  201. public function touch($path, $modificationTime = null);
  202. /**
  203. * Put contents into given file
  204. *
  205. * @param string $path
  206. * @param string $content
  207. * @param string|null $mode
  208. * @return int The number of bytes that were written.
  209. * @throws FileSystemException
  210. */
  211. public function filePutContents($path, $content, $mode = null);
  212. /**
  213. * Open file
  214. *
  215. * @param string $path
  216. * @param string $mode
  217. * @return resource
  218. * @throws FileSystemException
  219. */
  220. public function fileOpen($path, $mode);
  221. /**
  222. * Reads the line content from file pointer (with specified number of bytes from the current position).
  223. *
  224. * @param resource $resource
  225. * @param int $length
  226. * @param string $ending [optional]
  227. * @return string
  228. * @throws FileSystemException
  229. */
  230. public function fileReadLine($resource, $length, $ending = null);
  231. /**
  232. * Reads the specified number of bytes from the current position.
  233. *
  234. * @param resource $resource
  235. * @param int $length
  236. * @return string
  237. * @throws FileSystemException
  238. */
  239. public function fileRead($resource, $length);
  240. /**
  241. * Reads one CSV row from the file
  242. *
  243. * @param resource $resource
  244. * @param int $length [optional]
  245. * @param string $delimiter [optional]
  246. * @param string $enclosure [optional]
  247. * @param string $escape [optional]
  248. * @return array|bool|null
  249. * @throws FileSystemException
  250. */
  251. public function fileGetCsv($resource, $length = 0, $delimiter = ',', $enclosure = '"', $escape = '\\');
  252. /**
  253. * Returns position of read/write pointer
  254. *
  255. * @param resource $resource
  256. * @return int
  257. * @throws FileSystemException
  258. */
  259. public function fileTell($resource);
  260. /**
  261. * Seeks to the specified offset
  262. *
  263. * @param resource $resource
  264. * @param int $offset
  265. * @param int $whence
  266. * @return int
  267. * @throws FileSystemException
  268. */
  269. public function fileSeek($resource, $offset, $whence = SEEK_SET);
  270. /**
  271. * Returns true if pointer at the end of file or in case of exception
  272. *
  273. * @param resource $resource
  274. * @return boolean
  275. */
  276. public function endOfFile($resource);
  277. /**
  278. * Close file
  279. *
  280. * @param resource $resource
  281. * @return boolean
  282. * @throws FileSystemException
  283. */
  284. public function fileClose($resource);
  285. /**
  286. * Writes data to file
  287. *
  288. * @param resource $resource
  289. * @param string $data
  290. * @return int
  291. * @throws FileSystemException
  292. */
  293. public function fileWrite($resource, $data);
  294. /**
  295. * Writes one CSV row to the file.
  296. *
  297. * @param resource $resource
  298. * @param array $data
  299. * @param string $delimiter
  300. * @param string $enclosure
  301. * @return int
  302. * @throws FileSystemException
  303. */
  304. public function filePutCsv($resource, array $data, $delimiter = ',', $enclosure = '"');
  305. /**
  306. * Flushes the output
  307. *
  308. * @param resource $resource
  309. * @return bool
  310. * @throws FileSystemException
  311. */
  312. public function fileFlush($resource);
  313. /**
  314. * Lock file in selected mode
  315. *
  316. * @param resource $resource
  317. * @param int $lockMode
  318. * @return bool
  319. * @throws FileSystemException
  320. */
  321. public function fileLock($resource, $lockMode = LOCK_EX);
  322. /**
  323. * Unlock file
  324. *
  325. * @param resource $resource
  326. * @return bool
  327. * @throws FileSystemException
  328. */
  329. public function fileUnlock($resource);
  330. /**
  331. * @param string $basePath
  332. * @param string $path
  333. * @param string|null $scheme
  334. * @return mixed
  335. */
  336. public function getAbsolutePath($basePath, $path, $scheme = null);
  337. /**
  338. * @param string $path
  339. * @return mixed
  340. */
  341. public function getRealPath($path);
  342. /**
  343. * Return correct path for link
  344. *
  345. * @param string $path
  346. * @return mixed
  347. */
  348. public function getRealPathSafety($path);
  349. /**
  350. * @param string $basePath
  351. * @param null $path
  352. * @return mixed
  353. */
  354. public function getRelativePath($basePath, $path = null);
  355. }