PageRenderTime 24ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/src/YapepBase/File/IFileHandler.php

https://bitbucket.org/szeber/yapep_base
PHP | 341 lines | 27 code | 26 blank | 288 comment | 0 complexity | 6a7969e6110a9404bb69a633a1831d62 MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of YAPEPBase.
  4. *
  5. * @package YapepBase
  6. * @subpackage File
  7. * @copyright 2011 The YAPEP Project All rights reserved.
  8. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  9. */
  10. namespace YapepBase\File;
  11. /**
  12. * Interface for basic file and directory handler methods.
  13. *
  14. * @package YapepBase
  15. * @subpackage File
  16. */
  17. interface IFileHandler {
  18. /**
  19. * Sets the access and modification time of a file or directory.
  20. *
  21. * @link http://php.net/manual/en/function.touch.php
  22. *
  23. * @param string $path Tha path to the file or directory.
  24. * @param int $modificationTime The modification time to set (timestamp).
  25. * @param int $accessTime The access time to set(timestamp).
  26. *
  27. * @return void
  28. *
  29. * @throws \YapepBase\Exception\File\Exception If the operation failed.
  30. */
  31. public function touch($path, $modificationTime = null, $accessTime = null);
  32. /**
  33. * Makes a directory. Be aware that by default it is recursive.
  34. *
  35. * @link http://php.net/manual/en/function.mkdir.php
  36. *
  37. * @param string $path The directory or structure(in case of recursive mode) to create.
  38. * @param int $mode The mode (rights) of the created directory, use octal value.
  39. * @param bool $isRecursive If TRUE the whole structure will be created.
  40. *
  41. * @return void
  42. *
  43. * @throws \YapepBase\Exception\File\Exception If the operation failed.
  44. */
  45. public function makeDirectory($path, $mode = 0755, $isRecursive = true);
  46. /**
  47. * Writes the given content to a file.
  48. *
  49. * @link http://php.net/manual/en/function.file-put-contents.php
  50. *
  51. * @param string $path Path to the file.
  52. * @param mixed $data Can be either a string, an array or a stream resource.
  53. * @param bool $append If TRUE, the given data will appended after the already existent data.
  54. * @param bool $lock If TRUE, the file will be locked at the writing.
  55. *
  56. * @return int The byte count of the written data.
  57. *
  58. * @throws \YapepBase\Exception\File\Exception If the operation failed.
  59. */
  60. public function write($path, $data, $append = false, $lock = false);
  61. /**
  62. * Changes the owner group and user of the file.
  63. *
  64. * @link http://php.net/manual/en/function.chgrp.php
  65. * @link http://php.net/manual/en/function.chown.php
  66. *
  67. * @param string $path Path to the file or directory.
  68. * @param string|int $group Name of the group, or the identifier.
  69. * @param string|int $user Name of the user, or the identifier.
  70. *
  71. * @return void
  72. *
  73. * @throws \YapepBase\Exception\File\NotFoundException If the file was not found.
  74. * @throws \YapepBase\Exception\File\Exception If it failed to set the owner.
  75. */
  76. public function changeOwner($path, $group = null, $user = null);
  77. /**
  78. * Changes the mode of the file.
  79. *
  80. * @link http://php.net/manual/en/function.chmod.php
  81. *
  82. * @param string $path Path to the file or directory.
  83. * @param int $mode The mode to set, use octal values.
  84. *
  85. * @return void
  86. *
  87. * @throws \YapepBase\Exception\File\NotFoundException If the file was not found.
  88. * @throws \YapepBase\Exception\File\Exception If it failed to set the mode.
  89. */
  90. public function changeMode($path, $mode);
  91. /**
  92. * Copies a file.
  93. *
  94. * If the destination path already exists, it will be overwritten.
  95. *
  96. * @link http://php.net/manual/en/function.copy.php
  97. *
  98. * @param string $source Path to the source file.
  99. * @param string $destination The destination path.
  100. *
  101. * @return void
  102. *
  103. * @throws \YapepBase\Exception\File\NotFoundException If the source file was not found.
  104. * @throws \YapepBase\Exception\File\Exception If it failed to set the mode.
  105. */
  106. public function copy($source, $destination);
  107. /**
  108. * Deletes a file.
  109. *
  110. * @link http://php.net/manual/en/function.unlink.php
  111. *
  112. * @param string $path Path to the file.
  113. *
  114. * @return void
  115. *
  116. * @throws \YapepBase\Exception\File\NotFoundException If the given path is not found.
  117. * @throws \YapepBase\Exception\File\Exception If it failed to delete the file or the given path
  118. * is not a regular file.
  119. */
  120. public function remove($path);
  121. /**
  122. * Deletes a directory.
  123. *
  124. * @param string $path The directory to delete.
  125. * @param bool $isRecursive If TRUE the contents will be removed too.
  126. *
  127. * @throws \YapepBase\Exception\File\Exception If the given path is not empty, and recursive mode is off.
  128. * Or if the given path is not a valid directory, or deletion failed.
  129. *
  130. * @return void
  131. */
  132. public function removeDirectory($path, $isRecursive = false);
  133. /**
  134. * Moves the given file to the given destination.
  135. *
  136. * @link http://php.net/manual/en/function.rename.php
  137. * @link http://php.net/manual/en/function.move-uploaded-file.php
  138. *
  139. * @param string $sourcePath Path of the file to move.
  140. * @param string $destinationPath Destination of the moved file.
  141. * @param bool $checkIfIsUploaded If TRUE it will move the file only if the file was uploaded through HTTP.
  142. *
  143. * @throws \YapepBase\Exception\File\NotFoundException If the source file is not found.
  144. * @throws \YapepBase\Exception\File\Exception If the source file is not uploaded through HTTP and its checked
  145. * or the move failed.
  146. *
  147. * @return void
  148. */
  149. public function move($sourcePath, $destinationPath, $checkIfIsUploaded = false);
  150. /**
  151. * Returns the parent directory's path.
  152. *
  153. * @link http://php.net/manual/en/function.dirname.php
  154. *
  155. * @param string $path Path of the file or directory.
  156. *
  157. * @return string
  158. */
  159. public function getParentDirectory($path);
  160. /**
  161. * Returns the current working directory.
  162. *
  163. * @return string|bool The full path of the current directory or FALSE on failure.
  164. */
  165. public function getCurrentDirectory();
  166. /**
  167. * Reads entire file into a string.
  168. *
  169. * @link http://php.net/manual/en/function.file-get-contents.php
  170. *
  171. * @param string $path Path to the file to open
  172. * @param int $offset Offset where the reading starts on the original stream.
  173. * @param int $maxLength Maximum length of data read.
  174. *
  175. * @throws \YapepBase\Exception\File\NotFoundException If the given path does not exist.
  176. * @throws \YapepBase\Exception\File\Exception If the given path is not a file or the read failed.
  177. * @throws \YapepBase\Exception\ParameterException If the given maxLength is less then 0.
  178. *
  179. * @return string The content of the file, or FALSE on failure.
  180. */
  181. public function getAsString($path, $offset = -1, $maxLength = null);
  182. /**
  183. * Returns the list of files and directories at the given path.
  184. *
  185. * @param string $path The directory that will be scanned.
  186. *
  187. * @throws \YapepBase\Exception\File\NotFoundException If the given path does not exist.
  188. * @throws \YapepBase\Exception\File\Exception If the given path is not a directory.
  189. *
  190. * @return array
  191. */
  192. public function getList($path);
  193. /**
  194. * Lists the content of the given directory by glob.
  195. *
  196. * @link http://php.net/manual/en/function.glob.php
  197. *
  198. * @param string $path The path where the function should list.
  199. * @param string $pattern The pattern to match.
  200. * @param int $flags Flags to modify the behaviour of the search {@uses GLOB_*}.
  201. *
  202. * @throws \YapepBase\Exception\File\NotFoundException If the given path does not exist.
  203. * @throws \YapepBase\Exception\File\Exception If the given path is not a directory.
  204. *
  205. * @return array|bool The found path names, or FALSE on failure.
  206. */
  207. public function getListByGlob($path, $pattern, $flags = null);
  208. /**
  209. * Returns the file modification time.
  210. *
  211. * @link http://php.net/manual/en/function.filemtime.php
  212. *
  213. * @param string $path Path to the file or directory.
  214. *
  215. * @throws \YapepBase\Exception\File\NotFoundException If the given path does not exist.
  216. * @throws \YapepBase\Exception\File\Exception If we failed to get the modification time.
  217. *
  218. * @return int A unix timestamp, or FALSE on failure.
  219. */
  220. public function getModificationTime($path);
  221. /**
  222. * Returns the size of the file.
  223. *
  224. * @link http://php.net/manual/en/function.filesize.php
  225. *
  226. * @param string $path Path to the file.
  227. *
  228. * @throws \YapepBase\Exception\File\NotFoundException If the given path does not exist.
  229. * @throws \YapepBase\Exception\File\Exception If we failed to get the file size.
  230. *
  231. * @return int|bool The size of the file in bytes, or FALSE on failure.
  232. */
  233. public function getSize($path);
  234. /**
  235. * Checks if the given directory or file exists.
  236. *
  237. * @link http://php.net/manual/en/function.file-exists.php
  238. *
  239. * @param string $path Path to the file or directory.
  240. *
  241. * @return bool TRUE if it exits, FALSE if not.
  242. */
  243. public function checkIsPathExists($path);
  244. /**
  245. * Checks if the given path is a directory or not.
  246. *
  247. * @link http://php.net/manual/en/function.is-dir.php
  248. *
  249. * @param string $path The path to check.
  250. *
  251. * @return bool TRUE if it is a directory, FALSE if not.
  252. *
  253. * @throws \YapepBase\Exception\File\NotFoundException If the path does not exist.
  254. */
  255. public function checkIsDirectory($path);
  256. /**
  257. * Checks if the given path is a file or not.
  258. *
  259. * @link http://php.net/manual/en/function.is-file.php
  260. *
  261. * @param string $path The path to check.
  262. *
  263. * @return bool TRUE if it is a file, FALSE if not.
  264. *
  265. * @throws \YapepBase\Exception\File\NotFoundException If the path does not exits
  266. */
  267. public function checkIsFile($path);
  268. /**
  269. * Checks if the given path is a symbolic link or not.
  270. *
  271. * @link http://php.net/manual/en/function.is-link.php
  272. *
  273. * @param string $path The path to check.
  274. *
  275. * @return bool TRUE if it is a symlink, FALSE if not.
  276. *
  277. * @throws \YapepBase\Exception\File\NotFoundException If the path does not exits
  278. */
  279. public function checkIsSymlink($path);
  280. /**
  281. * Checks if the given path is readable.
  282. *
  283. * @link http://php.net/manual/en/function.is-writable.php
  284. *
  285. * @param string $path The path to check.
  286. *
  287. * @return bool TRUE if it is readable, FALSE if not.
  288. *
  289. * @throws \YapepBase\Exception\File\NotFoundException If the path does not exits
  290. */
  291. public function checkIsReadable($path);
  292. /**
  293. * Checks if the given path is writable.
  294. *
  295. * @link http://php.net/manual/en/function.is-writable.php
  296. *
  297. * @param string $path The path to check.
  298. *
  299. * @return bool TRUE if it is writable, FALSE if not.
  300. *
  301. * @throws \YapepBase\Exception\File\NotFoundException If the path does not exits
  302. */
  303. public function checkIsWritable($path);
  304. /**
  305. * Returns trailing name component of path
  306. *
  307. * @link http://php.net/manual/en/function.basename.php
  308. *
  309. * @param string $path The path.
  310. * @param string $suffix If the name component ends in suffix this will also be cut off.
  311. *
  312. * @return string
  313. */
  314. public function getBaseName($path, $suffix = null);
  315. }