]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blame - lib/User.php
Make getAll() return the list of users without wrapping it under a 'list' item.
[irc/unrealircd/unrealircd-rpc-php.git] / lib / User.php
CommitLineData
8d5a112f
D
1<?php
2
3namespace UnrealIRCd;
4
5use Exception;
80bc3098 6use stdClass;
8d5a112f 7
78796043 8class User
8d5a112f
D
9{
10
11 public Connection $connection;
12
7c7017a2 13 public function __construct(Connection $conn)
8d5a112f 14 {
7c7017a2 15 $this->connection = $conn;
8d5a112f
D
16 }
17
18 /**
19 * Return a list of all users.
20 *
21 * @throws Exception
22 */
93f8a3ee 23 public function getAll(): stdClass|array|bool
8d5a112f
D
24 {
25 $response = $this->connection->query('user.list');
26
27 if(!is_bool($response)) {
93f8a3ee 28 return $response->list;
8d5a112f
D
29 }
30
31 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
32 }
33
34 /**
35 * Return a user object
36 *
93f8a3ee 37 * @return stdClass|array|bool
8d5a112f
D
38 * @throws Exception
39 */
93f8a3ee 40 public function get(string $nick): stdClass|array|bool
8d5a112f 41 {
92f8fc2f 42 $response = $this->connection->query('user.get', ['nick' => $nick]);
8d5a112f
D
43
44 if (!is_bool($response)) {
45 return $response;
46 }
47
48 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
49 }
50}