|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace Spameri\ElasticQuery\Response\Result; |
| 4 | + |
| 5 | + |
| 6 | +class Version |
| 7 | +{ |
| 8 | + // 7 digits MAJOR|MAJOR|MINOR|MINOR|PATCH|PATCH |
| 9 | + public const ELASTIC_VERSION_ID_2 = 20000; |
| 10 | + public const ELASTIC_VERSION_ID_24 = 20400; |
| 11 | + public const ELASTIC_VERSION_ID_5 = 50000; |
| 12 | + public const ELASTIC_VERSION_ID_51 = 50100; |
| 13 | + public const ELASTIC_VERSION_ID_52 = 50200; |
| 14 | + public const ELASTIC_VERSION_ID_53 = 50300; |
| 15 | + public const ELASTIC_VERSION_ID_54 = 50400; |
| 16 | + public const ELASTIC_VERSION_ID_55 = 50500; |
| 17 | + public const ELASTIC_VERSION_ID_56 = 50600; |
| 18 | + public const ELASTIC_VERSION_ID_6 = 60000; |
| 19 | + public const ELASTIC_VERSION_ID_61 = 60100; |
| 20 | + public const ELASTIC_VERSION_ID_62 = 60200; |
| 21 | + public const ELASTIC_VERSION_ID_63 = 60300; |
| 22 | + public const ELASTIC_VERSION_ID_64 = 60400; |
| 23 | + public const ELASTIC_VERSION_ID_65 = 60500; |
| 24 | + public const ELASTIC_VERSION_ID_66 = 60600; |
| 25 | + public const ELASTIC_VERSION_ID_67 = 60700; |
| 26 | + public const ELASTIC_VERSION_ID_7 = 70000; |
| 27 | + public const ELASTIC_VERSION_ID_8 = 80000; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var string |
| 31 | + */ |
| 32 | + private $number; |
| 33 | + /** |
| 34 | + * @var int |
| 35 | + */ |
| 36 | + private $id; |
| 37 | + /** |
| 38 | + * @var string|NULL |
| 39 | + */ |
| 40 | + private $buildFlavor; |
| 41 | + /** |
| 42 | + * @var string|NULL |
| 43 | + */ |
| 44 | + private $buildType; |
| 45 | + /** |
| 46 | + * @var string |
| 47 | + */ |
| 48 | + private $buildHash; |
| 49 | + /** |
| 50 | + * @var string |
| 51 | + */ |
| 52 | + private $buildDate; |
| 53 | + /** |
| 54 | + * @var bool |
| 55 | + */ |
| 56 | + private $buildSnapshot; |
| 57 | + /** |
| 58 | + * @var string |
| 59 | + */ |
| 60 | + private $luceneVersion; |
| 61 | + /** |
| 62 | + * @var string|NULL |
| 63 | + */ |
| 64 | + private $minimumWireCompatibility; |
| 65 | + /** |
| 66 | + * @var string|NULL |
| 67 | + */ |
| 68 | + private $minimumIndexCompatibility; |
| 69 | + |
| 70 | + |
| 71 | + public function __construct( |
| 72 | + string $number |
| 73 | + , ?string $buildFlavor |
| 74 | + , ?string $buildType |
| 75 | + , string $buildHash |
| 76 | + , string $buildDate |
| 77 | + , bool $buildSnapshot |
| 78 | + , string $luceneVersion |
| 79 | + , ?string $minimumWireCompatibility |
| 80 | + , ?string $minimumIndexCompatibility |
| 81 | + ) |
| 82 | + { |
| 83 | + $this->number = $number; |
| 84 | + $this->id = $this->convertVersionNumber($number); |
| 85 | + $this->buildFlavor = $buildFlavor; |
| 86 | + $this->buildType = $buildType; |
| 87 | + $this->buildHash = $buildHash; |
| 88 | + $this->buildDate = $buildDate; |
| 89 | + $this->buildSnapshot = $buildSnapshot; |
| 90 | + $this->luceneVersion = $luceneVersion; |
| 91 | + $this->minimumWireCompatibility = $minimumWireCompatibility; |
| 92 | + $this->minimumIndexCompatibility = $minimumIndexCompatibility; |
| 93 | + } |
| 94 | + |
| 95 | + |
| 96 | + public function convertVersionNumber( |
| 97 | + string $number |
| 98 | + ): int |
| 99 | + { |
| 100 | + $exploded = \explode('.', $number); |
| 101 | + |
| 102 | + $major = (int) $exploded[0]; |
| 103 | + $version = $major * 10000; |
| 104 | + |
| 105 | + $minor = (int) $exploded[1]; |
| 106 | + $version += $minor * 100; |
| 107 | + |
| 108 | + $patch = (int) $exploded[2]; |
| 109 | + $version += $patch; |
| 110 | + |
| 111 | + return $version; |
| 112 | + } |
| 113 | + |
| 114 | + |
| 115 | + public function number() : string |
| 116 | + { |
| 117 | + return $this->number; |
| 118 | + } |
| 119 | + |
| 120 | + |
| 121 | + public function id() : int |
| 122 | + { |
| 123 | + return $this->id; |
| 124 | + } |
| 125 | + |
| 126 | + |
| 127 | + public function buildFlavor() : ?string |
| 128 | + { |
| 129 | + return $this->buildFlavor; |
| 130 | + } |
| 131 | + |
| 132 | + |
| 133 | + public function buildType() : ?string |
| 134 | + { |
| 135 | + return $this->buildType; |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | + public function buildHash() : string |
| 140 | + { |
| 141 | + return $this->buildHash; |
| 142 | + } |
| 143 | + |
| 144 | + |
| 145 | + public function buildDate() : string |
| 146 | + { |
| 147 | + return $this->buildDate; |
| 148 | + } |
| 149 | + |
| 150 | + |
| 151 | + public function buildSnapshot() : bool |
| 152 | + { |
| 153 | + return $this->buildSnapshot; |
| 154 | + } |
| 155 | + |
| 156 | + |
| 157 | + public function luceneVersion() : string |
| 158 | + { |
| 159 | + return $this->luceneVersion; |
| 160 | + } |
| 161 | + |
| 162 | + |
| 163 | + public function minimumWireCompatibility() : ?string |
| 164 | + { |
| 165 | + return $this->minimumWireCompatibility; |
| 166 | + } |
| 167 | + |
| 168 | + |
| 169 | + public function minimumIndexCompatibility() : ?string |
| 170 | + { |
| 171 | + return $this->minimumIndexCompatibility; |
| 172 | + } |
| 173 | + |
| 174 | +} |
0 commit comments