- md5
- 6e429c92ad801a1f306483024701db4f
- sha1
- 8c2cda0b47fb0ec3e82fddab166c9458fad91ef2
- sha256
- ac435c1eeebbd0896919c56ec220b6e80ea34774aba1e36c250d027a9ed84eb6
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\CMS\Application;
use Joomla\CMS\User\User;
use Joomla\CMS\User\UserFactoryInterface;
/**
* Trait for application classes which are identity (user) aware
*
* @since 4.0.0
*/
trait IdentityAware
{
/**
* The application identity object.
*
* @var User
* @since 4.0.0
*/
protected $identity;
/**
* UserFactoryInterface
*
* @var UserFactoryInterface
* @since 4.0.0
*/
private $userFactory;
/**
* Get the application identity.
*
* @return User
*
* @since 4.0.0
*/
public function getIdentity()
{
return $this->identity;
}
/**
* Allows the application to load a custom or default identity.
*
* @param User $identity An optional identity object. If omitted, a null user object is created.
*
* @return $this
*
* @since 4.0.0
*/
public function loadIdentity(User $identity = null)
{
$this->identity = $identity ?: $this->userFactory->loadUserById(0);
return $this;
}
/**
* Set the user factory to use.
*
* @param UserFactoryInterface $userFactory The user factory to use
*
* @return void
*
* @since 4.0.0
*/
public function setUserFactory(UserFactoryInterface $userFactory)
{
$this->userFactory = $userFactory;
}
}
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.