Skip to content

Commit 556b9f6

Browse files
committed
suggested legacy compatible method signatures
1 parent 6bb5d7a commit 556b9f6

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/Bolt.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Bolt;
44

5+
use Bolt\helpers\Auth;
56
use Bolt\error\{
67
ConnectException,
78
PackException,
@@ -180,17 +181,35 @@ private function packProtocolVersions(): string
180181

181182
/**
182183
* Send INIT message
183-
* @param array $extra You can use helpers\Auth to generate required array
184+
*
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
188+
* @param string|null $user
189+
* @param string|null $password
190+
* @param array|null $routing
191+
* @param array $metadata
192+
*
184193
* @return array
185194
* @throws Exception
186195
* @version <3
187196
*/
188-
public function init(array $extra): array
197+
public function init($nameOrExtra, string $user = null, string $password = null, array $routing = null, array $metadata = []): array
189198
{
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+
}
207+
}
208+
190209
if ($this->connection->connect() && $this->handshake()) {
191210
if (self::$debug)
192211
echo 'INIT';
193-
return $this->protocol->init($extra);
212+
return $this->protocol->init($nameOrExtra);
194213
}
195214

196215
// I don't think it will reach this point, but otherwise I've to end method with return
@@ -199,14 +218,22 @@ public function init(array $extra): array
199218

200219
/**
201220
* Send HELLO message
202-
* @param array $extra You can use helpers\Auth to generate required array
221+
*
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
228+
* @param array $metadata
229+
*
203230
* @return array
204231
* @throws Exception
205232
* @version >=3
206233
*/
207-
public function hello(array $extra): array
234+
public function hello($nameOrExtra, string $user = null, string $password = null, array $routing = null, array $metadata = []): array
208235
{
209-
return $this->init($extra);
236+
return $this->init($nameOrExtra, $user, $password, $routing, $metadata);
210237
}
211238

212239
/**

0 commit comments

Comments
 (0)