CacheEntry.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Files\Cache;
  8. use OCP\Files\Cache\ICacheEntry;
  9. /**
  10. * meta data for a file or folder
  11. */
  12. class CacheEntry implements ICacheEntry {
  13. /**
  14. * @var array
  15. */
  16. private $data;
  17. public function __construct(array $data) {
  18. $this->data = $data;
  19. }
  20. public function offsetSet($offset, $value): void {
  21. $this->data[$offset] = $value;
  22. }
  23. public function offsetExists($offset): bool {
  24. return isset($this->data[$offset]);
  25. }
  26. public function offsetUnset($offset): void {
  27. unset($this->data[$offset]);
  28. }
  29. /**
  30. * @return mixed
  31. */
  32. #[\ReturnTypeWillChange]
  33. public function offsetGet($offset) {
  34. if (isset($this->data[$offset])) {
  35. return $this->data[$offset];
  36. } else {
  37. return null;
  38. }
  39. }
  40. public function getId() {
  41. return (int)$this->data['fileid'];
  42. }
  43. public function getStorageId() {
  44. return $this->data['storage'];
  45. }
  46. public function getPath() {
  47. return (string)$this->data['path'];
  48. }
  49. public function getName() {
  50. return $this->data['name'];
  51. }
  52. public function getMimeType() {
  53. return $this->data['mimetype'];
  54. }
  55. public function getMimePart() {
  56. return $this->data['mimepart'];
  57. }
  58. public function getSize() {
  59. return $this->data['size'];
  60. }
  61. public function getMTime() {
  62. return $this->data['mtime'];
  63. }
  64. public function getStorageMTime() {
  65. return $this->data['storage_mtime'];
  66. }
  67. public function getEtag() {
  68. return $this->data['etag'];
  69. }
  70. public function getPermissions() {
  71. return $this->data['permissions'];
  72. }
  73. public function isEncrypted() {
  74. return isset($this->data['encrypted']) && $this->data['encrypted'];
  75. }
  76. public function getMetadataEtag(): ?string {
  77. return $this->data['metadata_etag'] ?? null;
  78. }
  79. public function getCreationTime(): ?int {
  80. return $this->data['creation_time'] ?? null;
  81. }
  82. public function getUploadTime(): ?int {
  83. return $this->data['upload_time'] ?? null;
  84. }
  85. public function getData() {
  86. return $this->data;
  87. }
  88. public function __clone() {
  89. $this->data = array_merge([], $this->data);
  90. }
  91. public function getUnencryptedSize(): int {
  92. if ($this->data['encrypted'] && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
  93. return $this->data['unencrypted_size'];
  94. } else {
  95. return $this->data['size'] ?? 0;
  96. }
  97. }
  98. }