3 * Value object representing a user's identity.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 namespace MediaWiki\User
;
25 use Wikimedia\Assert\Assert
;
28 * Value object representing a user's identity.
32 class UserIdentityValue
implements UserIdentity
{
54 public function __construct( $id, $name, $actor ) {
55 Assert
::parameterType( 'integer', $id, '$id' );
56 Assert
::parameterType( 'string', $name, '$name' );
57 Assert
::parameterType( 'integer', $actor, '$actor' );
61 $this->actor
= $actor;
65 * @return int The user ID. May be 0 for anonymous users or for users with no local account.
67 public function getId() {
72 * @return string The user's logical name. May be an IPv4 or IPv6 address for anonymous users.
74 public function getName() {
79 * @return int The user's actor ID. May be 0 if no actor ID has been assigned.
81 public function getActorId() {
88 * @param UserIdentity $user
91 public function equals( UserIdentity
$user ) {
92 // XXX it's not clear whether central ID providers are supposed to obey this
93 return $this->getName() === $user->getName();
99 * @return bool True if user is registered on this wiki, i.e., has a user ID. False if user is
100 * anonymous or has no local account (which can happen when importing). This is equivalent to
101 * getId() != 0 and is provided for code readability.
103 public function isRegistered() {
104 return $this->getId() != 0;