]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/User.php
This should be enough for some preliminary usage.
[irc/unrealircd/unrealircd-rpc-php.git] / lib / User.php
1 <?php
2
3 namespace UnrealIRCd;
4
5 use Exception;
6
7 class User implements Contracts\User
8 {
9
10 public Connection $connection;
11
12 public function __construct(string $uri, string $api_login, array $options)
13 {
14 $this->connection = new Connection($uri, $api_login, $options);
15 }
16
17 /**
18 * Return a list of all users.
19 *
20 * @throws Exception
21 */
22 public function get(): array
23 {
24 $response = $this->connection->query('user.list');
25
26 if(!is_bool($response)) {
27 return $response;
28 }
29
30 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
31 }
32
33 /**
34 * Return a user object
35 *
36 * @param array $params
37 * @return object|bool
38 * @throws Exception
39 */
40 public function show(array $params): object|bool
41 {
42 $response = $this->connection->query('user.get', ['nick' => $params['nick']]);
43
44 if (!is_bool($response)) {
45 return $response;
46 }
47
48 throw new Exception('Invalid JSON Response from UnrealIRCd RPC.');
49 }
50 }