- md5
- 8e54bf4c54f2cbe3544648c3ab6f1bc9
- sha1
- 1ceb44700dfd268c43cb8ee6874f6ca790d79db9
- sha256
- 3eccc217c4bf08f1de792780491e2f4e32a76ebb50c1b8038215925a166311e2
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\User;
defined('_JEXEC') or die;
use Joomla\Database\DatabaseInterface;
/**
* Default factory for creating User objects
*
* @since 4.0.0
*/
class UserFactory implements UserFactoryInterface
{
/**
* The database.
*
* @var DatabaseInterface
*/
private $db;
/**
* UserFactory constructor.
*
* @param DatabaseInterface $db The database
*/
public function __construct(DatabaseInterface $db)
{
$this->db = $db;
}
/**
* Method to get an instance of a user for the given id.
*
* @param int $id The id
*
* @return User
*
* @since 4.0.0
*/
public function loadUserById(int $id): User
{
return new User($id);
}
/**
* Method to get an instance of a user for the given username.
*
* @param string $username The username
*
* @return User
*
* @since 4.0.0
*/
public function loadUserByUsername(string $username): User
{
// Initialise some variables
$query = $this->db->getQuery(true)
->select($this->db->quoteName('id'))
->from($this->db->quoteName('#__users'))
->where($this->db->quoteName('username') . ' = ' . $this->db->quote($username));
$query->setLimit(1, 0);
$this->db->setQuery($query);
return $this->loadUserById((int) $this->db->loadResult());
}
}
The same content is in 4 releases, Joomla 4.0.0-alpha8 to 4.0.0-alpha11. See them all, or every version of this file.