homeobjectstorestorage.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @author Jörn Friedrich Dreyer
  4. * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public
  17. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. namespace OC\Files\ObjectStore;
  21. use OC\User\User;
  22. class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage {
  23. /**
  24. * The home user storage requires a user object to create a unique storage id
  25. * @param array $params
  26. */
  27. public function __construct($params) {
  28. if ( ! isset($params['user']) || ! $params['user'] instanceof User) {
  29. throw new \Exception('missing user object in parameters');
  30. }
  31. $this->user = $params['user'];
  32. parent::__construct($params);
  33. }
  34. public function getId () {
  35. return 'object::user:' . $this->user->getUID();
  36. }
  37. /**
  38. * get the owner of a path
  39. *
  40. * @param string $path The path to get the owner
  41. * @return false|string uid
  42. */
  43. public function getOwner($path) {
  44. if (is_object($this->user)) {
  45. return $this->user->getUID();
  46. }
  47. return false;
  48. }
  49. /**
  50. * @param string $path, optional
  51. * @return \OC\User\User
  52. */
  53. public function getUser($path = null) {
  54. return $this->user;
  55. }
  56. }