Token.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OC\DirectEditing;
  7. use OCP\DirectEditing\IToken;
  8. use OCP\Files\File;
  9. class Token implements IToken {
  10. /** @var Manager */
  11. private $manager;
  12. private $data;
  13. public function __construct(Manager $manager, $data) {
  14. $this->manager = $manager;
  15. $this->data = $data;
  16. }
  17. public function extend(): void {
  18. $this->manager->refreshToken($this->data['token']);
  19. }
  20. public function invalidate(): void {
  21. $this->manager->invalidateToken($this->data['token']);
  22. }
  23. public function getFile(): File {
  24. if ($this->data['share_id'] !== null) {
  25. return $this->manager->getShareForToken($this->data['share_id']);
  26. }
  27. return $this->manager->getFileForToken($this->data['user_id'], $this->data['file_id'], $this->data['file_path']);
  28. }
  29. public function getToken(): string {
  30. return $this->data['token'];
  31. }
  32. public function useTokenScope(): void {
  33. $this->manager->invokeTokenScope($this->data['user_id']);
  34. }
  35. public function hasBeenAccessed(): bool {
  36. return (bool) $this->data['accessed'];
  37. }
  38. public function getEditor(): string {
  39. return $this->data['editor_id'];
  40. }
  41. public function getUser(): string {
  42. return $this->data['user_id'];
  43. }
  44. }