-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathConnectionProtocol.php
More file actions
99 lines (87 loc) · 2.52 KB
/
Copy pathConnectionProtocol.php
File metadata and controls
99 lines (87 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
/*
* This file is part of the Neo4j PHP Client and Driver package.
*
* (c) Nagels <https://nagels.tech>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Laudis\Neo4j\Enum;
use Bolt\protocol\V4;
use Bolt\protocol\V4_1;
use Bolt\protocol\V4_2;
use Bolt\protocol\V4_3;
use Bolt\protocol\V4_4;
use Bolt\protocol\V5;
use Bolt\protocol\V5_1;
use Bolt\protocol\V5_2;
use Bolt\protocol\V5_3;
use Bolt\protocol\V5_4;
use JsonSerializable;
use Laudis\TypedEnum\TypedEnum;
/**
* Defines the protocol used in a connection.
*
* @method static ConnectionProtocol BOLT_V3()
* @method static ConnectionProtocol BOLT_V40()
* @method static ConnectionProtocol BOLT_V41()
* @method static ConnectionProtocol BOLT_V42()
* @method static ConnectionProtocol BOLT_V43()
* @method static ConnectionProtocol BOLT_V44()
* @method static ConnectionProtocol BOLT_V5()
* @method static ConnectionProtocol BOLT_V5_1()
* @method static ConnectionProtocol BOLT_V5_2()
* @method static ConnectionProtocol BOLT_V5_3()
* @method static ConnectionProtocol BOLT_V5_4()
*
* @extends TypedEnum<string>
*
* @psalm-immutable
*
* @psalm-suppress MutableDependency
*/
final class ConnectionProtocol extends TypedEnum implements JsonSerializable
{
private const BOLT_V3 = '3';
private const BOLT_V40 = '4';
private const BOLT_V41 = '4.1';
private const BOLT_V42 = '4.2';
private const BOLT_V43 = '4.3';
private const BOLT_V44 = '4.4';
private const BOLT_V5 = '5';
private const BOLT_V5_1 = '5.1';
private const BOLT_V5_2 = '5.2';
private const BOLT_V5_3 = '5.3';
private const BOLT_V5_4 = '5.4';
/**
* @pure
*
* @psalm-suppress ImpureMethodCall
*/
public static function determineBoltVersion(V4|V4_1|V4_2|V4_3|V4_4|V5|V5_1|V5_2|V5_3|V5_4 $bolt): self
{
$version = self::resolve($bolt->getVersion());
return $version[0] ?? self::BOLT_V44();
}
public function compare(ConnectionProtocol $protocol): int
{
$x = 0;
$y = 0;
/** @psalm-suppress ImpureMethodCall */
foreach (array_values(self::getAllInstances()) as $index => $instance) {
if ($instance === $this) {
$x = $index;
}
if ($instance === $protocol) {
$y = $index;
}
}
return $x - $y;
}
public function jsonSerialize(): string
{
return $this->getValue();
}
}