CoreFiles by mySites.guru
UserFactory.php75 lines, 1,506 bytes, from Joomla_4.0.0-alpha12-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha11
md5
77b88159919ea32d16c8cb64951a836d
sha1
da5cb71f3e0b1232ec22f56b3bb152362f40492c
sha256
e7db749b389efedeff5b9440112c6ef1bf33a1a27383d1c65669a2431be8e449
<?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') . ' = :username')
			->bind(':username', $username)
			->setLimit(1);
		$this->db->setQuery($query);

		return $this->loadUserById((int) $this->db->loadResult());
	}
}

No other release has this exact content. See every version of this file.