- md5
- daca19f313bba5670a79ec2156d977b9
- sha1
- 7fb0e1d52dc9cbdbc2cc0bc4a6b0d6e35016b4a8
- sha256
- 2c44283a8c21bb8935e9e6e629edb46ea72383349d554c1e7d3bb3c3191f0f51
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\User;
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') . ' = :username')
->bind(':username', $username)
->setLimit(1);
$this->db->setQuery($query);
return $this->loadUserById((int) $this->db->loadResult());
}
}
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.