]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace UnrealIRCd; | |
4 | ||
5 | use Exception; | |
6 | use stdClass; | |
7 | ||
8 | class User implements Contracts\User | |
9 | { | |
10 | ||
11 | public Connection $connection; | |
12 | ||
13 | public function __construct(Connection $conn) | |
14 | { | |
15 | $this->connection = $conn; | |
16 | } | |
17 | ||
18 | /** | |
19 | * Return a list of all users. | |
20 | * | |
21 | * @throws Exception | |
22 | */ | |
23 | public function getAll(): stdClass | |
24 | { | |
25 | $response = $this->connection->query('user.list'); | |
26 | ||
27 | if(!is_bool($response)) { | |
28 | return $response; | |
29 | } | |
30 | ||
31 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
32 | } | |
33 | ||
34 | /** | |
35 | * Return a user object | |
36 | * | |
37 | * @param array $params | |
38 | * @return stdClass | |
39 | * @throws Exception | |
40 | */ | |
41 | public function get(array $params): stdClass | |
42 | { | |
43 | $response = $this->connection->query('user.get', ['nick' => $params['nick']]); | |
44 | ||
45 | if (!is_bool($response)) { | |
46 | return $response; | |
47 | } | |
48 | ||
49 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
50 | } | |
51 | } |