Skip to content

Commit ccc79df

Browse files
committed
added route message spec
1 parent f35f549 commit ccc79df

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Bolt.php

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

33
namespace Bolt;
44

5+
use Bolt\protocol\V4_3;
56
use Bolt\error\{
67
ConnectException,
78
PackException,
@@ -11,6 +12,8 @@
1112
use Bolt\PackStream\{IPacker, IUnpacker};
1213
use Bolt\protocol\AProtocol;
1314
use Bolt\connection\IConnection;
15+
use function get_called_class;
16+
use function method_exists;
1417

1518
/**
1619
* Main class Bolt
@@ -388,4 +391,18 @@ public function __destruct()
388391
$this->connection->disconnect();
389392
}
390393

394+
/**
395+
* fetch the current routing table, if the message specification allows it.
396+
*
397+
* @param array $routing
398+
* @return array|null
399+
*/
400+
public function route(array $routing): ?array
401+
{
402+
if (!method_exists($this->protocol, 'route')) {
403+
return null;
404+
}
405+
406+
return $this->protocol->route($routing);
407+
}
391408
}

src/protocol/V4_3.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Bolt\protocol;
44

5+
use Bolt\error\MessageException;
6+
use Bolt\error\PackException;
7+
use function count;
8+
use function is_array;
9+
510
/**
611
* Class Protocol version 4.3
712
*
@@ -11,5 +16,17 @@
1116
*/
1217
class V4_3 extends V4_1
1318
{
19+
public function route(array $routing): array
20+
{
21+
$this->write($this->packer->pack(0x66, $routing));
22+
23+
$signature = 0;
24+
$output = $this->read($signature);
25+
26+
if ($signature === self::FAILURE) {
27+
throw new MessageException($output['message'] . ' (' . $output['code'] . ')');
28+
}
1429

30+
return $signature === self::SUCCESS ? $output : [];
31+
}
1532
}

0 commit comments

Comments
 (0)