File.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV;
  4. /**
  5. * File class.
  6. *
  7. * This is a helper class, that should aid in getting file classes setup.
  8. * Most of its methods are implemented, and throw permission denied exceptions
  9. *
  10. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  11. * @author Evert Pot (http://evertpot.com/)
  12. * @license http://sabre.io/license/ Modified BSD License
  13. */
  14. abstract class File extends Node implements IFile
  15. {
  16. /**
  17. * Replaces the contents of the file.
  18. *
  19. * The data argument is a readable stream resource.
  20. *
  21. * After a successful put operation, you may choose to return an ETag. The
  22. * etag must always be surrounded by double-quotes. These quotes must
  23. * appear in the actual string you're returning.
  24. *
  25. * Clients may use the ETag from a PUT request to later on make sure that
  26. * when they update the file, the contents haven't changed in the mean
  27. * time.
  28. *
  29. * If you don't plan to store the file byte-by-byte, and you return a
  30. * different object on a subsequent GET you are strongly recommended to not
  31. * return an ETag, and just return null.
  32. *
  33. * @param string|resource $data
  34. *
  35. * @return string|null
  36. */
  37. public function put($data)
  38. {
  39. throw new Exception\Forbidden('Permission denied to change data');
  40. }
  41. /**
  42. * Returns the data.
  43. *
  44. * This method may either return a string or a readable stream resource
  45. *
  46. * @return mixed
  47. */
  48. public function get()
  49. {
  50. throw new Exception\Forbidden('Permission denied to read this file');
  51. }
  52. /**
  53. * Returns the size of the file, in bytes.
  54. *
  55. * @return int
  56. */
  57. public function getSize()
  58. {
  59. return 0;
  60. }
  61. /**
  62. * Returns the ETag for a file.
  63. *
  64. * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
  65. * The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
  66. *
  67. * Return null if the ETag can not effectively be determined
  68. *
  69. * @return string|null
  70. */
  71. public function getETag()
  72. {
  73. return null;
  74. }
  75. /**
  76. * Returns the mime-type for a file.
  77. *
  78. * If null is returned, we'll assume application/octet-stream
  79. *
  80. * @return string|null
  81. */
  82. public function getContentType()
  83. {
  84. return null;
  85. }
  86. }