response.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * @author Andreas Fischer <bantu@owncloud.com>
  4. * @author Bart Visscher <bartv@thisnet.nl>
  5. * @author Frank Karlitschek <frank@owncloud.org>
  6. * @author Lukas Reschke <lukas@owncloud.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <icewind@owncloud.com>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  11. *
  12. * @copyright Copyright (c) 2016, ownCloud, Inc.
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. /**
  29. * Public interface of ownCloud for apps to use.
  30. * Response Class.
  31. *
  32. */
  33. // use OCP namespace for all classes that are considered public.
  34. // This means that they should be used by apps instead of the internal ownCloud classes
  35. namespace OCP;
  36. /**
  37. * This class provides convenient functions to send the correct http response headers
  38. * @since 4.0.0
  39. * @deprecated 8.1.0 - Use AppFramework controllers instead and modify the response object
  40. */
  41. class Response {
  42. /**
  43. * Enable response caching by sending correct HTTP headers
  44. * @param int $cache_time time to cache the response
  45. * >0 cache time in seconds
  46. * 0 and <0 enable default browser caching
  47. * null cache indefinitely
  48. * @since 4.0.0
  49. */
  50. static public function enableCaching( $cache_time = null ) {
  51. \OC_Response::enableCaching( $cache_time );
  52. }
  53. /**
  54. * Checks and set Last-Modified header, when the request matches sends a
  55. * 'not modified' response
  56. * @param string $lastModified time when the response was last modified
  57. * @since 4.0.0
  58. */
  59. static public function setLastModifiedHeader( $lastModified ) {
  60. \OC_Response::setLastModifiedHeader( $lastModified );
  61. }
  62. /**
  63. * Sets the content disposition header (with possible workarounds)
  64. * @param string $filename file name
  65. * @param string $type disposition type, either 'attachment' or 'inline'
  66. * @since 7.0.0
  67. */
  68. static public function setContentDispositionHeader( $filename, $type = 'attachment' ) {
  69. \OC_Response::setContentDispositionHeader( $filename, $type );
  70. }
  71. /**
  72. * Sets the content length header (with possible workarounds)
  73. * @param string|int|float $length Length to be sent
  74. * @since 8.1.0
  75. */
  76. static public function setContentLengthHeader($length) {
  77. \OC_Response::setContentLengthHeader($length);
  78. }
  79. /**
  80. * Disable browser caching
  81. * @see enableCaching with cache_time = 0
  82. * @since 4.0.0
  83. */
  84. static public function disableCaching() {
  85. \OC_Response::disableCaching();
  86. }
  87. /**
  88. * Checks and set ETag header, when the request matches sends a
  89. * 'not modified' response
  90. * @param string $etag token to use for modification check
  91. * @since 4.0.0
  92. */
  93. static public function setETagHeader( $etag ) {
  94. \OC_Response::setETagHeader( $etag );
  95. }
  96. /**
  97. * Send file as response, checking and setting caching headers
  98. * @param string $filepath of file to send
  99. * @since 4.0.0
  100. * @deprecated 8.1.0 - Use \OCP\AppFramework\Http\StreamResponse or another AppFramework controller instead
  101. */
  102. static public function sendFile( $filepath ) {
  103. \OC_Response::sendFile( $filepath );
  104. }
  105. /**
  106. * Set response expire time
  107. * @param string|\DateTime $expires date-time when the response expires
  108. * string for DateInterval from now
  109. * DateTime object when to expire response
  110. * @since 4.0.0
  111. */
  112. static public function setExpiresHeader( $expires ) {
  113. \OC_Response::setExpiresHeader( $expires );
  114. }
  115. /**
  116. * Send redirect response
  117. * @param string $location to redirect to
  118. * @since 4.0.0
  119. */
  120. static public function redirect( $location ) {
  121. \OC_Response::redirect( $location );
  122. }
  123. }