Skip to content

Commit 0c1b003

Browse files
Updated changes to keep backwards compatibility.
1 parent 556b9f6 commit 0c1b003

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

src/Bolt.php

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -182,58 +182,56 @@ private function packProtocolVersions(): string
182182
/**
183183
* Send INIT message
184184
*
185-
* @note The usage of $user, $password, $routing and $metadata is deprecated. Please use helpers\Auth to generate an authentication strategy as an array.
186-
*
187-
* @param array|string $nameOrExtra You can use helpers\Auth to generate required array or use the deprecated approach to fill in $name, $user and $password
185+
* @param array|string $userAgentOrExtra You can use helpers\Auth to generate required array or use the deprecated approach to fill in $name, $user and $password
188186
* @param string|null $user
189187
* @param string|null $password
190-
* @param array|null $routing
188+
* @param array|null|bool $routing
191189
* @param array $metadata
192190
*
193-
* @return array
191+
* @return bool
194192
* @throws Exception
193+
* @deprecated The usage of $user, $password, $routing and $metadata is deprecated. Please use helpers\Auth to generate an authentication strategy as an array.
194+
*
195195
* @version <3
196196
*/
197-
public function init($nameOrExtra, string $user = null, string $password = null, array $routing = null, array $metadata = []): array
197+
public function init($userAgentOrExtra, string $user = '', string $password = '', $routing = false, array &$metadata = []): bool
198198
{
199-
if (is_string($nameOrExtra)) {
200-
$nameOrExtra = Auth::basic($user, $password);
201-
if ($routing) {
202-
$nameOrExtra['routing'] = $routing;
203-
}
204-
if ($metadata) {
205-
$nameOrExtra['metaData'] = $metadata;
206-
}
199+
if (is_string($userAgentOrExtra)) {
200+
Auth::$userAgent = $userAgentOrExtra;
201+
$userAgentOrExtra = Auth::basic($user, $password);
202+
if ($routing !== false)
203+
$userAgentOrExtra['routing'] = $routing;
207204
}
208205

209206
if ($this->connection->connect() && $this->handshake()) {
210207
if (self::$debug)
211208
echo 'INIT';
212-
return $this->protocol->init($nameOrExtra);
209+
$metadata = $this->protocol->init($userAgentOrExtra);
210+
return true;
213211
}
214212

215213
// I don't think it will reach this point, but otherwise I've to end method with return
216-
throw new Exception('INIT message wasn\'t successful');
214+
throw new Exception('INIT message failed');
217215
}
218216

219217
/**
220218
* Send HELLO message
221219
*
222-
* @note The usage of $user, $password, $routing and $metadata is deprecated. Please use helpers\Auth to generate an authentication strategy as an array.
223-
*
224-
* @param array|string $nameOrExtra You can use helpers\Auth to generate required array or use the deprecated approach to fill in $name, $user and $password
225-
* @param string|null $user
226-
* @param string|null $password
227-
* @param array|null $routing
220+
* @param array|string $userAgentOrExtra You can use helpers\Auth to generate required array or use the deprecated approach to fill in $name, $user and $password
221+
* @param string $user
222+
* @param string $password
223+
* @param array|null|bool $routing
228224
* @param array $metadata
229225
*
230-
* @return array
226+
* @return bool
231227
* @throws Exception
228+
* @deprecated The usage of $user, $password, $routing and $metadata is deprecated. Please use helpers\Auth to generate an authentication strategy as an array.
229+
*
232230
* @version >=3
233231
*/
234-
public function hello($nameOrExtra, string $user = null, string $password = null, array $routing = null, array $metadata = []): array
232+
public function hello($userAgentOrExtra, string $user = '', string $password = '', $routing = false, array &$metadata = []): bool
235233
{
236-
return $this->init($nameOrExtra, $user, $password, $routing, $metadata);
234+
return $this->init($userAgentOrExtra, $user, $password, $routing, $metadata);
237235
}
238236

239237
/**

0 commit comments

Comments
 (0)