mirror of
https://github.com/nextcloud/server.git
synced 2025-01-30 22:37:01 +00:00
c1555fc33e
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
58 lines
975 B
PHP
58 lines
975 B
PHP
<?php
|
|
/**
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
namespace OCA\Files_External\Service;
|
|
|
|
use OCP\IUser;
|
|
use OCP\IUserSession;
|
|
|
|
/**
|
|
* Trait for getting user information in a service
|
|
*/
|
|
trait UserTrait {
|
|
|
|
/** @var IUserSession */
|
|
protected $userSession;
|
|
|
|
/**
|
|
* User override
|
|
*
|
|
* @var IUser|null
|
|
*/
|
|
private $user = null;
|
|
|
|
/**
|
|
* @return IUser|null
|
|
*/
|
|
protected function getUser() {
|
|
if ($this->user) {
|
|
return $this->user;
|
|
}
|
|
return $this->userSession->getUser();
|
|
}
|
|
|
|
/**
|
|
* Override the user from the session
|
|
* Unset with ->resetUser() when finished!
|
|
*
|
|
* @param IUser $user
|
|
* @return self
|
|
*/
|
|
public function setUser(IUser $user) {
|
|
$this->user = $user;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Reset the user override
|
|
*
|
|
* @return self
|
|
*/
|
|
public function resetUser() {
|
|
$this->user = null;
|
|
return $this;
|
|
}
|
|
}
|