]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blob - lib/User.php
Added version to composer.json and a couple of small (hopefully non-breaking) changes
[irc/unrealircd/unrealircd-rpc-php.git] / lib / User.php
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(string $uri, string $api_login, array $options)
14 {
15 $this->connection = new Connection($uri, $api_login, $options);
16 }
17
18 /**
19 * Return a list of all users.
20 *
21 * @throws Exception
22 */
23 public function get(): 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 show(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 }