- md5
- c020518181596d792aacbd3c4a277531
- sha1
- 829d309b2b930f0509124012ae50ea1f31b106e3
- sha256
- 31bcd044053f7fec6e07640d681f8fd5cfea6a1e625e9687a9ff8388a75f1574
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2020 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') . ' = :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.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.