- md5
- 911815d508ecb7adfcd766729d882b35
- sha1
- ba3a7c6ea1dc8cf9c95ce5b412f4db7ac3491fee
- sha256
- 2d4c5b28b800e85f9dfbc366643f0e97b8a1648b705e50daccda4cdf7ada81d2
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\CMS\User;
use Joomla\CMS\Factory;
/**
* Trait for classes which require a user to work with.
*
* @since 4.2.0
*/
trait CurrentUserTrait
{
/**
* The current user object.
*
* @var User
* @since 4.2.0
*/
private $currentUser;
/**
* Returns the current user, if none is set the identity of the global app
* is returned. This will change in 5.0 and an empty user will be returned.
*
* @return User
*
* @since 4.2.0
*/
protected function getCurrentUser(): User
{
if (!$this->currentUser) {
@trigger_error(
sprintf('User must be set in %s. This will not be caught anymore in 5.0', __METHOD__),
E_USER_DEPRECATED
);
$this->currentUser = Factory::getApplication()->getIdentity() ?: Factory::getUser();
}
return $this->currentUser;
}
/**
* Sets the current user.
*
* @param User $currentUser The current user object
*
* @return void
*
* @since 4.2.0
*/
public function setCurrentUser(User $currentUser): void
{
$this->currentUser = $currentUser;
}
}
The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.