]>
Commit | Line | Data |
---|---|---|
8d5a112f D |
1 | <?php |
2 | ||
3 | namespace UnrealIRCd; | |
4 | ||
5 | use Exception; | |
80bc3098 | 6 | use stdClass; |
8d5a112f D |
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 | */ | |
80bc3098 | 23 | public function get(): 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 | */ | |
80bc3098 | 41 | public function show(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 | } |