1 | <?php |
||
16 | final class UnpackOptions |
||
17 | { |
||
18 | public const BIGINT_AS_STR = 0b001; |
||
19 | public const BIGINT_AS_GMP = 0b010; |
||
20 | public const BIGINT_AS_EXCEPTION = 0b100; |
||
21 | |||
22 | private $bigIntMode; |
||
23 | |||
24 | 246 | private function __construct() |
|
27 | |||
28 | 232 | public static function fromDefaults() : self |
|
29 | { |
||
30 | 232 | $self = new self(); |
|
31 | 232 | $self->bigIntMode = self::BIGINT_AS_STR; |
|
32 | |||
33 | 232 | return $self; |
|
34 | } |
||
35 | |||
36 | 21 | public static function fromBitmask(int $bitmask) : self |
|
37 | { |
||
38 | 21 | $self = new self(); |
|
39 | |||
40 | 21 | $self->bigIntMode = self::getSingleOption('bigint', $bitmask, |
|
41 | 21 | self::BIGINT_AS_STR | |
|
42 | 21 | self::BIGINT_AS_GMP | |
|
43 | 21 | self::BIGINT_AS_EXCEPTION |
|
44 | 3 | ) ?: self::BIGINT_AS_STR; |
|
45 | |||
46 | 16 | return $self; |
|
47 | } |
||
48 | |||
49 | 237 | public function isBigIntAsStrMode() : bool |
|
50 | { |
||
51 | 237 | return self::BIGINT_AS_STR === $this->bigIntMode; |
|
52 | } |
||
53 | |||
54 | 237 | public function isBigIntAsGmpMode() : bool |
|
58 | |||
59 | 4 | public function isBigIntAsExceptionMode() : bool |
|
60 | { |
||
61 | 4 | return self::BIGINT_AS_EXCEPTION === $this->bigIntMode; |
|
63 | |||
64 | 21 | private static function getSingleOption(string $name, int $bitmask, int $validBitmask) : int |
|
84 | } |
||
85 |