CoreFiles by mySites.guru
IdentityAware.php83 lines, 1,738 bytes, from Joomla_4.3.2-Stable-Full_Package.zip
Raw History Compare with 4.3.1
md5
3885f8b2745a7e6423ce1c85ec5e7196
sha1
e1883a0279331db7020a81e9b6cf4676566028dc
sha256
a7c738a04a44217a82f84749cb739ad40a3183e56bcefd69e0ca0f5ba883c001
<?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.txt
 */

namespace Joomla\CMS\Application;

use Joomla\CMS\User\User;
use Joomla\CMS\User\UserFactoryInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * 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 6 releases, Joomla 4.3.2-rc1 to 4.3.4. See them all, or every version of this file.