Skip to content

Commit 577124d

Browse files
committed
removed stored version from bolt factory
1 parent 047fd6e commit 577124d

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/Bolt.php

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ final class Bolt
3939
*/
4040
private $versions = [4.4, 4.3, 4.2, 3];
4141

42-
/**
43-
* @var float
44-
*/
45-
private $version;
46-
4742
/**
4843
* Print debug info
4944
* @var bool
@@ -71,11 +66,11 @@ public function build(): AProtocol
7166
if (!$this->connection->connect())
7267
throw new ConnectException('Connection failed');
7368

74-
$this->handshake();
69+
$version = $this->handshake();
7570

76-
$protocolClass = "\\Bolt\\protocol\\V" . str_replace('.', '_', $this->version);
71+
$protocolClass = "\\Bolt\\protocol\\V" . str_replace('.', '_', $version);
7772
if (!class_exists($protocolClass))
78-
throw new ConnectException('Requested Protocol version (' . $this->version . ') not yet implemented');
73+
throw new ConnectException('Requested Protocol version (' . $version . ') not yet implemented');
7974

8075
return new $protocolClass($this->packer, $this->unpacker, $this->connection);
8176
}
@@ -112,45 +107,38 @@ public function setPackStreamVersion(int $version = 1): Bolt
112107
return $this;
113108
}
114109

115-
/**
116-
* Version is available after successful connection with init/hello message
117-
* @return float
118-
*/
119-
public function getProtocolVersion(): float
120-
{
121-
return $this->version;
122-
}
123-
124110
/**
125111
* @link https://7687.org/bolt/bolt-protocol-handshake-specification.html
126112
* @throws Exception
127113
*/
128-
private function handshake()
114+
private function handshake(): float
129115
{
130116
if (self::$debug)
131117
echo 'HANDSHAKE';
132118

133119
$this->connection->write(chr(0x60) . chr(0x60) . chr(0xb0) . chr(0x17));
134120
$this->connection->write($this->packProtocolVersions());
135121

136-
$this->unpackProtocolVersion();
137-
if (empty($this->version))
122+
$version = $this->unpackProtocolVersion();
123+
if (empty($version))
138124
throw new ConnectException('Wrong version');
125+
126+
return $version;
139127
}
140128

141129
/**
142130
* Read and compose selected protocol version
143131
*/
144-
private function unpackProtocolVersion()
132+
private function unpackProtocolVersion(): float
145133
{
146134
$result = [];
147135

148136
foreach (str_split($this->connection->read(4)) as $ch)
149137
$result[] = unpack('C', $ch)[1] ?? 0;
150138

151-
$result = array_filter($result);
152139
$result = array_reverse($result);
153-
$this->version = implode('.', $result);
140+
141+
return (float) implode('.', $result);
154142
}
155143

156144
/**

0 commit comments

Comments
 (0)