Skip to content

Commit 38a4e57

Browse files
Merge pull request #95 from neo4j-php/additional_version_check
Additional version check
2 parents 5cf5a7d + 25ece31 commit 38a4e57

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Bolt.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public function build(): AProtocol
6161
*/
6262
public function setProtocolVersions(...$v): Bolt
6363
{
64-
$this->versions = $v;
64+
$this->versions = array_slice($v, 0, 4);
65+
while (count($this->versions) < 4)
66+
$this->versions[] = 0;
6567
return $this;
6668
}
6769

@@ -109,9 +111,9 @@ private function handshake(): string
109111

110112
/**
111113
* Read and compose selected protocol version
112-
* @return string
114+
* @return string|null
113115
*/
114-
private function unpackProtocolVersion(): string
116+
private function unpackProtocolVersion(): ?string
115117
{
116118
$result = [];
117119

@@ -123,7 +125,8 @@ private function unpackProtocolVersion(): string
123125
array_shift($result);
124126
}
125127

126-
return implode('.', array_reverse($result));
128+
$version = implode('.', array_reverse($result));
129+
return in_array($version, $this->versions) ? $version : null;
127130
}
128131

129132
/**
@@ -134,9 +137,6 @@ private function packProtocolVersions(): string
134137
{
135138
$versions = [];
136139

137-
while (count($this->versions) < 4)
138-
$this->versions[] = '0';
139-
140140
foreach ($this->versions as $v) {
141141
if (is_int($v))
142142
$versions[] = pack('N', $v);

0 commit comments

Comments
 (0)