PageRenderTime 25ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/kernel/private/interfaces/ezclusterfilehandlerinterface.php

https://github.com/Yannix/ezpublish
PHP | 401 lines | 47 code | 42 blank | 312 comment | 0 complexity | 644d65cb2d90c9fce477355f9b67de5f MD5 | raw file
  1. <?php
  2. /**
  3. * File containing the eZClusterFileHandlerInterface interface.
  4. *
  5. * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
  6. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
  7. * @version //autogentag//
  8. * @package lib
  9. */
  10. /**
  11. * Cluster file handlers interface
  12. */
  13. interface eZClusterFileHandlerInterface
  14. {
  15. /**
  16. * Stores a file by path to the backend
  17. *
  18. * @param string $filePath Path to the file being stored.
  19. * @param string $scope Means something like "file category". May be used
  20. * to clean caches of a certain type.
  21. * @param bool $delete true if the file should be deleted after storing.
  22. * @param string $datatype
  23. *
  24. * @return void
  25. */
  26. public function fileStore( $filePath, $scope = false, $delete = false, $datatype = false );
  27. /**
  28. *
  29. * Store file contents.
  30. *
  31. * @param string $filePath Path to the file being stored.
  32. * @param string $contents Binary file content
  33. * @param string $scope "file category". May be used by cache management
  34. * @param string $datatype Datatype for the file. Also used to clean cache up
  35. *
  36. * @return void
  37. */
  38. public function fileStoreContents( $filePath, $contents, $scope = false, $datatype = false );
  39. /**
  40. * Store file contents using binary data
  41. *
  42. * @param string $contents Binary file content
  43. * @param string $scope "file category". May be used by cache management
  44. * @param string $datatype Datatype for the file. Also used to clean cache up
  45. * @param bool $storeLocally If true the file will also be stored on the
  46. * local file system.
  47. */
  48. public function storeContents( $contents, $scope = false, $datatype = false, $storeLocally = false );
  49. /**
  50. * Fetches a file locally
  51. *
  52. * @param string $filePath
  53. *
  54. * @return string|false the file path, or false if fetching failed
  55. */
  56. public function fileFetch( $filePath );
  57. /**
  58. * Handles cache requests / write operations
  59. *
  60. * Creates a single transaction out of the typical file operations for
  61. * accessing caches. Caches are normally ready from the database or local
  62. * file, if the entry does not exist or is expired then it generates the new
  63. * cache data and stores it. This method takes care of these operations and
  64. * handles the custom code by performing callbacks when needed.
  65. *
  66. * The $retrieveCallback is used when the file contents can be used (ie. not
  67. * re-generation) and is called when the file is ready locally.
  68. * The function will be called with the file path as the first parameter, the
  69. * mtime as the second and optionally $extraData as the third.
  70. * The function must return the file contents or an instance of
  71. * eZClusterFileFailure which can be used to tell the system that the
  72. * retrieve data cannot be used after all.
  73. *
  74. * $retrieveCallback can be set to null which makes the system go directly
  75. * to the generation.
  76. *
  77. * The $generateCallback is used when the file content is expired or does not
  78. * exist, in this case the content must be re-generated and stored. The
  79. * function will be called with the file path as the first parameter and
  80. * optionally $extraData as the second.
  81. * The function must return an array with information on the contents, the
  82. * array consists of:
  83. * - scope - The current scope of the file, is optional.
  84. * - datatype - The current datatype of the file, is optional.
  85. * - content - The file content, this can be any type except null.
  86. * - binarydata - The binary data which is written to the file.
  87. * - store - Whether *content* or *binarydata* should be stored to the
  88. * file, if false it will simply return the data. Optional,
  89. * by default it is true.
  90. * Note: Set $generateCallback to false to disable generation callback.
  91. * Note: Set $generateCallback to null to tell the function to perform a
  92. * write lock but not do any generation, the generation must done be
  93. * done by the caller by calling @see storeCache().
  94. *
  95. * Either *content* or *binarydata* must be supplied, if not an error is
  96. * issued and it returns null.
  97. *
  98. * If *content* is set it will be used as the return value of this function,
  99. * if not it will return the binary data.
  100. * If *binarydata* is set it will be used as the binary data for the file, if
  101. * not it will perform a var_export on *content* and use that as the binary
  102. * data.
  103. *
  104. * For convenience the $generateCallback function can return a string which
  105. * will be considered as the binary data for the file and returned as the
  106. * content.
  107. *
  108. * For controlling how long a cache entry can be used the parameters
  109. * @see $expiry and @see $ttl is used.
  110. * @see $expiry can be set to a timestamp which controls the absolute max
  111. * time for the cache, after this time/date the cache will never be used.
  112. * If the value is set to a negative value or null there the expiration check
  113. * is disabled.
  114. *
  115. * $ttl (time to live) tells how many seconds the cache can live from the
  116. * time it was stored. If the value is set to negative or null there is no
  117. * limit for the lifetime of the cache. A value of 0 means that the cache
  118. * will always expire and practically disables caching. For the cache to be
  119. * used both the $expiry and $ttl check must hold.
  120. *
  121. * @todo Reformat the doc so that it's readable
  122. */
  123. public function processCache( $retrieveCallback, $generateCallback = null, $ttl = null, $expiry = null, $extraData = null );
  124. /**
  125. * Calculates if the file data is expired or not.
  126. *
  127. * @param string $fname Name of file, available for easy debugging.
  128. * @param int $mtime Modification time of file, can be set to false if
  129. * file does not exist.
  130. * @param int $expiry Time when file is to be expired, a value of -1 will
  131. * disable this check.
  132. * @param int $curtime The current time to check against.
  133. * @param int $ttl Number of seconds the data can live, set to null to
  134. * disable TTL.
  135. * @return bool
  136. */
  137. public function isFileExpired( $fname, $mtime, $expiry, $curtime, $ttl );
  138. /**
  139. * Calculates if the current file data is expired or not.
  140. *
  141. * @param int $expiry Time when file is to be expired, a value of -1 will disable this check.
  142. * @param int $curtime The current time to check against.
  143. * @param int $ttl Number of seconds the data can live, set to null to disable TTL.
  144. * @return bool
  145. */
  146. public function isExpired( $expiry, $curtime, $ttl );
  147. /**
  148. * Calculates if the local file is expired or not.
  149. * @param int $expiry Time when file is to be expired, a value of -1 will disable this check.
  150. * @param int $curtime The current time to check against.
  151. * @param int $ttl Number of seconds the data can live, set to null to disable TTL.
  152. * @return bool
  153. */
  154. public function isLocalFileExpired( $expiry, $curtime, $ttl );
  155. /**
  156. * Calculates if the DB file is expired or not.
  157. * @param int $expiry Time when file is to be expired, a value of -1 will disable this check.
  158. * @param int $curtime The current time to check against.
  159. * @param int $ttl Number of seconds the data can live, set to null to disable TTL.
  160. * @return bool
  161. */
  162. public function isDBFileExpired( $expiry, $curtime, $ttl );
  163. /**
  164. * Provides access to the file contents by downloading the file locally and
  165. * calling $callback with the local filename. The callback can then process
  166. * the contents and return the data in the same way as in processCache().
  167. *
  168. * Downloading is only done once so the local copy is kept, while updates to
  169. * the remote DB entry is synced with the local one.
  170. *
  171. * The parameters $expiry and $extraData is the same as for processCache().
  172. *
  173. * @see self::processCache()
  174. * @note Unlike processCache() this returns null if the file cannot be
  175. * accessed.
  176. */
  177. public function processFile( $callback, $expiry = false, $extraData = null );
  178. /**
  179. * Fetches a cluster file and saves it locally under a new name
  180. *
  181. * @return string path to the saved file
  182. */
  183. public function fetchUnique();
  184. /**
  185. * Fetches file from db and saves it in FS under the same name.
  186. * @param bool $noLocalCache
  187. */
  188. function fetch( $noLocalCache = false );
  189. /**
  190. * Returns file contents.
  191. * @return contents string, or false in case of an error.
  192. */
  193. public function fileFetchContents( $filePath );
  194. /**
  195. * Returns file contents.
  196. * @return string|bool contents string, or false in case of an error.
  197. */
  198. public function fetchContents();
  199. /**
  200. * Returns file metadata.
  201. */
  202. public function stat();
  203. /**
  204. * Returns file size.
  205. * @return int|null
  206. */
  207. public function size();
  208. /**
  209. * Returns file modification time.
  210. * @return int|null
  211. */
  212. public function mtime();
  213. /**
  214. * Returns file name.
  215. * @return string
  216. */
  217. public function name();
  218. /**
  219. * @note has severe performance issues
  220. */
  221. public function fileDeleteByRegex( $dir, $fileRegex );
  222. /**
  223. * @note has some severe performance issues
  224. */
  225. public function fileDeleteByWildcard( $wildcard );
  226. public function fileDeleteByDirList( $dirList, $commonPath, $commonSuffix );
  227. /**
  228. * Deletes specified file/directory.
  229. *
  230. * If a directory specified it is deleted recursively.
  231. */
  232. public function fileDelete( $path, $fnamePart = false );
  233. /**
  234. * Deletes specified file/directory.
  235. *
  236. * If a directory specified it is deleted recursively.
  237. */
  238. public function delete();
  239. /**
  240. * Deletes a file that has been fetched before.
  241. */
  242. public function fileDeleteLocal( $path );
  243. /**
  244. * Deletes a file that has been fetched before.
  245. */
  246. public function deleteLocal();
  247. /**
  248. * Purges local and remote file data for current file.
  249. */
  250. public function purge( $printCallback = false, $microsleep = false, $max = false, $expiry = false );
  251. /**
  252. * Check if given file/dir exists.
  253. * @param string $file
  254. * @return bool
  255. */
  256. public function fileExists( $path );
  257. /**
  258. * Check if given file/dir exists.
  259. *
  260. * @note This function does not interact with database. Instead, it just
  261. * returns existance status determined in the constructor.
  262. *
  263. * @return bool
  264. */
  265. public function exists();
  266. /**
  267. * Outputs file contents prepending them with appropriate HTTP headers.
  268. *
  269. * @deprecated This function should not be used since it cannot handle
  270. * reading errors.
  271. */
  272. public function passthrough();
  273. /**
  274. * Copy file.
  275. */
  276. public function fileCopy( $srcPath, $dstPath );
  277. /**
  278. * Create symbolic or hard link to file.
  279. */
  280. public function fileLinkCopy( $srcPath, $dstPath, $symLink );
  281. /**
  282. * Move file.
  283. */
  284. public function fileMove( $srcPath, $dstPath );
  285. /**
  286. * Move file.
  287. * @param string $dstPath Destination path
  288. */
  289. public function move( $dstPath );
  290. /**
  291. * Get list of files stored in database.
  292. *
  293. * Used in bin/php/clusterize.php.
  294. *
  295. * @param array $scopes return only files that belong to any of these scopes
  296. * @param boolean $excludeScopes if true, then reverse the meaning of $scopes, which is
  297. * return only files that do not belong to any of the scopes listed in $scopes
  298. */
  299. public function getFileList( $scopes = false, $excludeScopes = false );
  300. /**
  301. * Starts cache generation for the current file.
  302. *
  303. * This is done by creating a file named by the original file name, prefixed
  304. * with '.generating'.
  305. *
  306. * @return bool false if the file is being generated, true if it is not
  307. */
  308. public function startCacheGeneration();
  309. /**
  310. * Ends the cache generation started by startCacheGeneration().
  311. */
  312. public function endCacheGeneration( $rename = true );
  313. /**
  314. * Aborts the current cache generation process.
  315. *
  316. * Does so by rolling back the current transaction, which should be the
  317. * .generating file lock
  318. */
  319. public function abortCacheGeneration();
  320. /**
  321. * Checks if the .generating file was changed, which would mean that generation
  322. * timed out. If not timed out, refreshes the timestamp so that storage won't
  323. * be stolen
  324. */
  325. public function checkCacheGenerationTimeout();
  326. /**
  327. * This method indicates if the cluster file handler requires clusterizing.
  328. *
  329. * If the handler does require clusterizing, it will be required/possible to
  330. * use bin/php/clusterize.php to get data in/out of the cluster when setting
  331. * it up or disabling it.
  332. *
  333. * @return bool
  334. */
  335. public function requiresClusterizing();
  336. /**
  337. * This method indicates if the cluster file handler requires binary files
  338. * to be purged in order to be physically deleted
  339. *
  340. * @since 4.3
  341. * @deprecated Deprecated as of 4.5, use {@link eZClusterFileHandlerInterface::requiresPurge()} instead.
  342. * @return bool
  343. */
  344. public function requiresBinaryPurge();
  345. /**
  346. * This method indicates if the cluster file handler requires binary files
  347. * to be purged in order to be physically deleted
  348. *
  349. * @since 4.5
  350. * @return bool
  351. */
  352. public function requiresPurge();
  353. /**
  354. * Indicates if the handler supports the stalecache feature
  355. * @return bool true if it does, false otherwise
  356. */
  357. public function hasStaleCacheSupport();
  358. }
  359. ?>