Back to Factory class

Method getUser

public static \Joomla\CMS\User\User
getUser
(mixed $id = null)
Get a user object.
Parameters
  • int $id The user to load - Can be an integer or string - If string, it is converted to ID automatically.
Returns
  • \Joomla\CMS\User\User object
Since
  • 1.7.0
Deprecated
  • 5.0
-
  • \Joomla\CMS\User\User
Class: Factory
Project: Joomla

Method getUser - Source code

/**
 * Get a user object.
 *
 * Returns the global {@link User} object, only creating it if it doesn't already exist.
 *
 * @param   integer  $id  The user to load - Can be an integer or string - If string, it is converted to ID automatically.
 *
 * @return  User object
 *
 * @see         User
 * @since       1.7.0
 * @deprecated  5.0  Load the user service from the dependency injection container or via $app->getIdentity()
 */
public static function getUser($id = null)
{
    @trigger_error(sprintf('%1$s() is deprecated. Load the user from the dependency injection container or via %2$s::getApplication()->getIdentity().', __METHOD__, __CLASS__), E_USER_DEPRECATED);
    $instance = self::getApplication()->getSession()->get('user');
    if (\is_null($id)) {
        if (!$instance instanceof User) {
            $instance = User::getInstance();
        }
    } elseif (!$instance instanceof User || \is_string($id) || $instance->id !== $id) {
        $instance = User::getInstance($id);
    }
    return $instance;
}