CacheEntry.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Files\Cache;
  24. use OCP\Files\Cache\ICacheEntry;
  25. /**
  26. * meta data for a file or folder
  27. */
  28. class CacheEntry implements ICacheEntry {
  29. /**
  30. * @var array
  31. */
  32. private $data;
  33. public function __construct(array $data) {
  34. $this->data = $data;
  35. }
  36. public function offsetSet($offset, $value): void {
  37. $this->data[$offset] = $value;
  38. }
  39. public function offsetExists($offset): bool {
  40. return isset($this->data[$offset]);
  41. }
  42. public function offsetUnset($offset): void {
  43. unset($this->data[$offset]);
  44. }
  45. /**
  46. * @return mixed
  47. */
  48. #[\ReturnTypeWillChange]
  49. public function offsetGet($offset) {
  50. if (isset($this->data[$offset])) {
  51. return $this->data[$offset];
  52. } else {
  53. return null;
  54. }
  55. }
  56. public function getId() {
  57. return (int)$this->data['fileid'];
  58. }
  59. public function getStorageId() {
  60. return $this->data['storage'];
  61. }
  62. public function getPath() {
  63. return (string)$this->data['path'];
  64. }
  65. public function getName() {
  66. return $this->data['name'];
  67. }
  68. public function getMimeType() {
  69. return $this->data['mimetype'];
  70. }
  71. public function getMimePart() {
  72. return $this->data['mimepart'];
  73. }
  74. public function getSize() {
  75. return $this->data['size'];
  76. }
  77. public function getMTime() {
  78. return $this->data['mtime'];
  79. }
  80. public function getStorageMTime() {
  81. return $this->data['storage_mtime'];
  82. }
  83. public function getEtag() {
  84. return $this->data['etag'];
  85. }
  86. public function getPermissions() {
  87. return $this->data['permissions'];
  88. }
  89. public function isEncrypted() {
  90. return isset($this->data['encrypted']) && $this->data['encrypted'];
  91. }
  92. public function getMetadataEtag(): ?string {
  93. return $this->data['metadata_etag'] ?? null;
  94. }
  95. public function getCreationTime(): ?int {
  96. return $this->data['creation_time'] ?? null;
  97. }
  98. public function getUploadTime(): ?int {
  99. return $this->data['upload_time'] ?? null;
  100. }
  101. public function getData() {
  102. return $this->data;
  103. }
  104. public function __clone() {
  105. $this->data = array_merge([], $this->data);
  106. }
  107. public function getUnencryptedSize(): int {
  108. if ($this->data['encrypted'] && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
  109. return $this->data['unencrypted_size'];
  110. } else {
  111. return $this->data['size'] ?? 0;
  112. }
  113. }
  114. }