1 | <?php |
||
10 | final class RocketChat |
||
11 | { |
||
12 | /** @var \GuzzleHttp\Client */ |
||
13 | private $http; |
||
14 | |||
15 | /** @var string */ |
||
16 | private $url; |
||
17 | |||
18 | /** @var string */ |
||
19 | private $token; |
||
20 | |||
21 | /** @var string|null */ |
||
22 | private $defaultChannel; |
||
23 | |||
24 | /** |
||
25 | * @param \GuzzleHttp\Client $http |
||
26 | * @param string $url |
||
27 | * @param string $token |
||
28 | * @param string|null $defaultChannel |
||
29 | * @return void |
||
|
|||
30 | */ |
||
31 | 4 | public function __construct(HttpClient $http, string $url, string $token, ?string $defaultChannel = null) |
|
38 | |||
39 | /** |
||
40 | * Returns RocketChat base url. |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function url(): string |
||
45 | { |
||
46 | return $this->url; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns RocketChat token. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | 1 | public function token(): string |
|
55 | { |
||
56 | 1 | return $this->token; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Returns default channel id or name. |
||
61 | * |
||
62 | * @return string|null |
||
63 | */ |
||
64 | 1 | public function defaultChannel(): ?string |
|
65 | { |
||
66 | 1 | return $this->defaultChannel; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Send a message. |
||
71 | * |
||
72 | * @param string $to |
||
73 | * @param array $message |
||
74 | * @return \Psr\Http\Message\ResponseInterface |
||
75 | */ |
||
76 | 2 | public function sendMessage(string $to, array $message): ResponseInterface |
|
86 | |||
87 | /** |
||
88 | * Perform a simple post request. |
||
89 | * |
||
90 | * @param string $url |
||
91 | * @param array $options |
||
92 | * @return \Psr\Http\Message\ResponseInterface |
||
93 | */ |
||
94 | 2 | private function post(string $url, array $options): ResponseInterface |
|
98 | } |
||
99 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.