]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blame_incremental - lib/User.php
Major API break:
[irc/unrealircd/unrealircd-rpc-php.git] / lib / User.php
... / ...
CommitLineData
1<?php
2
3namespace UnrealIRCd;
4
5use Exception;
6use stdClass;
7
8class 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}