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 */ |
||
22 | private $channel; |
||
23 | |||
24 | /** |
||
25 | * @param \GuzzleHttp\Client $http |
||
26 | * @param string $url |
||
27 | * @param string $token |
||
28 | * @param string $channel |
||
29 | * @return void |
||
|
|||
30 | */ |
||
31 | public function __construct(HttpClient $http, $url, $token, $channel) |
||
32 | { |
||
33 | $this->http = $http; |
||
34 | $this->url = rtrim($url, '/'); |
||
35 | $this->token = $token; |
||
36 | $this->channel = $channel; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Returns default channel id or name. |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function channel(): string |
||
45 | { |
||
46 | return $this->channel; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns RocketChat base url. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function url(): string |
||
58 | |||
59 | /** |
||
60 | * Returns RocketChat token. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | public function token(): string |
||
68 | |||
69 | /** |
||
70 | * Send a message. |
||
71 | * |
||
72 | * @param string|int $to |
||
73 | * @param array $message |
||
74 | * @return \Psr\Http\Message\ResponseInterface |
||
75 | */ |
||
76 | public function sendMessage($to, $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 | private function post($url, $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.