Response.php 4.1 KB

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