summaryrefslogtreecommitdiff
path: root/bin/reevotech/vendor/addwiki/mediawiki-datamodel/src/User.php
blob: fca5ddf324902c5d3a6d2e15aac535c707def36c (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php

namespace Mediawiki\DataModel;

use InvalidArgumentException;

/**
 * Represents a mediawiki user
 * @author Addshore
 */
class User {

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

	/**
	 * @var int
	 */
	private $id;

	/**
	 * @var int
	 */
	private $editcount;

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

	/**
	 * @var array
	 */
	private $groups;

	/**
	 * @var array
	 */
	private $rights;

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

	/**
	 * @param string $name
	 * @param int $id
	 * @param int $editcount
	 * @param string $registration
	 * @param array[] $groups groups grouped by type.
	 *          Keys to use are 'groups' and 'implicitgroups' as returned by the api.
	 * @param array $rights
	 * @param string $gender
	 *
	 * @throws InvalidArgumentException
	 */
	public function __construct( $name, $id, $editcount, $registration, $groups, $rights, $gender ) {
		if( !is_string( $name ) || empty( $name ) ) {
			throw new InvalidArgumentException( '$name must be a string and can not be empty' );
		}
		if( !is_int( $id ) ) {
			throw new InvalidArgumentException( '$id must be an int' );
		}
		if( !is_int( $editcount ) ) {
			throw new InvalidArgumentException( '$editcount must be an int' );
		}
		if( !is_array( $groups ) || !array_key_exists( 'groups', $groups ) || !array_key_exists( 'implicitgroups', $groups ) ) {
			throw new InvalidArgumentException( '$groups must be an array or arrays with keys "groups" and "implicitgroups"' );
		}
		if( !is_array( $rights ) ) {
			throw new InvalidArgumentException( '$rights must be an array' );
		}
		if( !is_string( $gender ) ) {
			throw new InvalidArgumentException( '$gender must be a string' );
		}

		$this->editcount = $editcount;
		$this->gender = $gender;
		$this->groups = $groups;
		$this->id = $id;
		$this->name = $name;
		$this->registration = $registration;
		$this->rights = $rights;
	}

	/**
	 * @return int
	 */
	public function getEditcount() {
		return $this->editcount;
	}

	/**
	 * @return string
	 */
	public function getGender() {
		return $this->gender;
	}

	/**
	 * @param string $type 'groups' or 'implicitgroups'
	 *
	 * @return array
	 */
	public function getGroups( $type = 'groups' ) {
		return $this->groups[$type];
	}

	/**
	 * @return int
	 */
	public function getId() {
		return $this->id;
	}

	/**
	 * @return string
	 */
	public function getName() {
		return $this->name;
	}

	/**
	 * @return string
	 */
	public function getRegistration() {
		return $this->registration;
	}

	/**
	 * @return array
	 */
	public function getRights() {
		return $this->rights;
	}

}