Skip to content

Commit 1115510

Browse files
committed
Update Socket.php
1 parent 9ff1ffc commit 1115510

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/Socket.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ class Socket
1212
{
1313
use LoggerAwareTrait;
1414

15+
/**
16+
* Auth
17+
*
18+
* @var \Botika\Socket\Auth
19+
*/
20+
protected Auth $auth;
21+
1522
/**
1623
* Http Client
1724
*
@@ -28,21 +35,21 @@ class Socket
2835
'connect_timeout' => 10,
2936
'http_errors' => false,
3037
'timeout' => 30,
38+
'verify' => false,
3139
];
3240

3341
/**
3442
* Constructor.
3543
*
44+
* @param string $baseURL
3645
* @param \Botika\Socket\Auth $auth
37-
* @param array $config
3846
*/
39-
public function __construct(Auth $auth, array $config = [])
47+
public function __construct(string $baseURL, Auth $auth)
4048
{
41-
$this->httpClient = new Client(
42-
array_merge($config, $this->httpClientDefaultConfig, [
43-
'auth' => $auth->toArray()
44-
])
45-
);
49+
$this->auth = $auth;
50+
$this->httpClient = new Client(array_merge($this->httpClientDefaultConfig, [
51+
'base_uri' => $baseURL
52+
]));
4653
}
4754

4855
/**
@@ -88,33 +95,37 @@ protected function log(string $message, array $context = [], string $level = Log
8895
*
8996
* @param string|array $channels
9097
* @param string $event
91-
* @param array|null $data
98+
* @param array|string|null $data
99+
* @param array $config
92100
* @return \Psr\Http\Message\ResponseInterface
93101
*/
94-
public function trigger(string|array $channels, string $event, array|null $data): ResponseInterface
102+
public function trigger(string|array $channels, string $event, array|string|null $data = null, array $config = []): ResponseInterface
95103
{
96104
$this->log('Botika Socket Trigger', $this->makeJsonRequest($channels, $event, $data));
97105

98-
return $this->httpClient->post('/events', [
106+
return $this->httpClient->post('/events', array_merge($config, [
107+
'auth' => $this->auth->toArray(),
99108
'json' => $this->makeJsonRequest($channels, $event, $data),
100-
]);
109+
]));
101110
}
102111

103112
/**
104113
* Asynchronously trigger an event by providing event name and payload.
105114
* Optionally provide a socket ID to exclude a client (most likely the sender).
106115
*
107-
* @param string|array $channels
116+
* @param string|array $channels
108117
* @param string $event
109-
* @param array|null $data
118+
* @param array|string|null $data
119+
* @param array $config
110120
* @return \GuzzleHttp\Promise\PromiseInterface
111121
*/
112-
public function triggerAsync(string|array $channels, string $event, array|null $data): PromiseInterface
122+
public function triggerAsync(string|array $channels, string $event, array|string|null $data = null, array $config = []): PromiseInterface
113123
{
114124
$this->log('Botika Socket Trigger Asynchronously', $this->makeJsonRequest($channels, $event, $data));
115125

116-
return $this->httpClient->postAsync('/events', [
126+
return $this->httpClient->postAsync('/events', array_merge($config, [
127+
'auth' => $this->auth->toArray(),
117128
'json' => $this->makeJsonRequest($channels, $event, $data),
118-
]);
129+
]));
119130
}
120131
}

0 commit comments

Comments
 (0)