HomeObjectStoreStorage.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OC\Files\ObjectStore;
  27. use OC\User\User;
  28. use OCP\IUser;
  29. class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage {
  30. /**
  31. * The home user storage requires a user object to create a unique storage id
  32. * @param array $params
  33. */
  34. public function __construct($params) {
  35. if (! isset($params['user']) || ! $params['user'] instanceof User) {
  36. throw new \Exception('missing user object in parameters');
  37. }
  38. $this->user = $params['user'];
  39. parent::__construct($params);
  40. }
  41. public function getId() {
  42. return 'object::user:' . $this->user->getUID();
  43. }
  44. /**
  45. * get the owner of a path
  46. *
  47. * @param string $path The path to get the owner
  48. * @return false|string uid
  49. */
  50. public function getOwner($path) {
  51. if (is_object($this->user)) {
  52. return $this->user->getUID();
  53. }
  54. return false;
  55. }
  56. /**
  57. * @param string $path, optional
  58. * @return \OC\User\User
  59. */
  60. public function getUser($path = null): IUser {
  61. return $this->user;
  62. }
  63. }