]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blame - lib/User.php
Major API break:
[irc/unrealircd/unrealircd-rpc-php.git] / lib / User.php
CommitLineData
8d5a112f
D
1<?php
2
3namespace UnrealIRCd;
4
5use Exception;
80bc3098 6use stdClass;
8d5a112f
D
7
8class User implements Contracts\User
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 */
7c7017a2 23 public function getAll(): stdClass
8d5a112f
D
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
80bc3098 38 * @return stdClass
8d5a112f
D
39 * @throws Exception
40 */
7c7017a2 41 public function get(array $params): stdClass
8d5a112f
D
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}