summaryrefslogtreecommitdiff
path: root/bin/reevotech/vendor/addwiki/mediawiki-api-base/src/ApiUser.php
blob: b2f591537c722e2c58fec42d30a86b8305e06279 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

namespace Mediawiki\Api;

use InvalidArgumentException;

/**
 * @since 0.1
 *
 * @author Addshore
 * @author RobinR1
 * @author Bene
 *
 * Represents a user that can log in to the api
 */
class ApiUser {

	/**
	 * @var string
	 */
	private $password;

	/**
	 * @var string
	 */
	private $username;

	/**
	 * @var string
	 */
	private $domain;

	/**
	 * @param string $username The username.
	 * @param string $password The user's password.
	 * @param string|null $domain The domain (for authentication systems that support domains).
	 *
	 * @throws \InvalidArgumentException
	 */
	public function __construct( $username, $password, $domain = null ) {
		$domainIsStringOrNull = ( is_string( $domain ) || is_null( $domain ) );
		if ( !is_string( $username ) || !is_string( $password ) || !$domainIsStringOrNull ) {
			throw new InvalidArgumentException( 'Username, Password and Domain must all be strings' );
		}
		if ( empty( $username ) || empty( $password ) ) {
			throw new InvalidArgumentException( 'Username and Password are not allowed to be empty' );
		}
		$this->username = $username;
		$this->password = $password;
		$this->domain   = $domain;
	}

	/**
	 * @since 0.1
	 * @return string
	 */
	public function getUsername() {
		return $this->username;
	}

	/**
	 * @since 0.1
	 * @return string
	 */
	public function getPassword() {
		return $this->password;
	}

	/**
	 * @since 0.1
	 * @return string
	 */
	public function getDomain() {
		return $this->domain;
	}

	/**
	 * @since 0.1
	 * @param mixed $other Another ApiUser object to compare with.
	 *
	 * @return bool
	 */
	public function equals( $other ) {
		return $other instanceof self
			&& $this->username == $other->getUsername()
			&& $this->password == $other->getPassword()
			&& $this->domain == $other->getDomain();
	}

}