PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Sabre/DAV/SimpleFile.php

https://github.com/KOLANICH/SabreDAV
PHP | 121 lines | 27 code | 24 blank | 70 comment | 0 complexity | bec597bb7878cb734915a729c7c9806f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. namespace Sabre\DAV;
  3. /**
  4. * SimpleFile
  5. *
  6. * The 'SimpleFile' class is used to easily add read-only immutable files to
  7. * the directory structure. One usecase would be to add a 'readme.txt' to a
  8. * root of a webserver with some standard content.
  9. *
  10. * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
  11. * @author Evert Pot (http://evertpot.com/)
  12. * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  13. */
  14. class SimpleFile extends File {
  15. /**
  16. * File contents
  17. *
  18. * @var string
  19. */
  20. protected $contents = array();
  21. /**
  22. * Name of this resource
  23. *
  24. * @var string
  25. */
  26. protected $name;
  27. /**
  28. * A mimetype, such as 'text/plain' or 'text/html'
  29. *
  30. * @var string
  31. */
  32. protected $mimeType;
  33. /**
  34. * Creates this node
  35. *
  36. * The name of the node must be passed, as well as the contents of the
  37. * file.
  38. *
  39. * @param string $name
  40. * @param string $contents
  41. * @param string|null $mimeType
  42. */
  43. public function __construct($name, $contents, $mimeType = null) {
  44. $this->name = $name;
  45. $this->contents = $contents;
  46. $this->mimeType = $mimeType;
  47. }
  48. /**
  49. * Returns the node name for this file.
  50. *
  51. * This name is used to construct the url.
  52. *
  53. * @return string
  54. */
  55. public function getName() {
  56. return $this->name;
  57. }
  58. /**
  59. * Returns the data
  60. *
  61. * This method may either return a string or a readable stream resource
  62. *
  63. * @return mixed
  64. */
  65. public function get() {
  66. return $this->contents;
  67. }
  68. /**
  69. * Returns the size of the file, in bytes.
  70. *
  71. * @return int
  72. */
  73. public function getSize() {
  74. return strlen($this->contents);
  75. }
  76. /**
  77. * Returns the ETag for a file
  78. *
  79. * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
  80. * The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
  81. *
  82. * Return null if the ETag can not effectively be determined
  83. * @return string
  84. */
  85. public function getETag() {
  86. return '"' . md5($this->contents) . '"';
  87. }
  88. /**
  89. * Returns the mime-type for a file
  90. *
  91. * If null is returned, we'll assume application/octet-stream
  92. * @return string
  93. */
  94. public function getContentType() {
  95. return $this->mimeType;
  96. }
  97. }