@@ -12,25 +12,25 @@ |
||
12 | 12 | */ |
13 | 13 | class VideotexString extends PrimitiveString |
14 | 14 | { |
15 | - use UniversalClass; |
|
15 | + use UniversalClass; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Constructor. |
|
19 | - * |
|
20 | - * @param string $string |
|
21 | - */ |
|
22 | - public function __construct(string $string) |
|
23 | - { |
|
24 | - $this->_typeTag = self::TYPE_VIDEOTEX_STRING; |
|
25 | - parent::__construct($string); |
|
26 | - } |
|
17 | + /** |
|
18 | + * Constructor. |
|
19 | + * |
|
20 | + * @param string $string |
|
21 | + */ |
|
22 | + public function __construct(string $string) |
|
23 | + { |
|
24 | + $this->_typeTag = self::TYPE_VIDEOTEX_STRING; |
|
25 | + parent::__construct($string); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _validateString(string $string): bool |
|
32 | - { |
|
33 | - // allow everything |
|
34 | - return true; |
|
35 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _validateString(string $string): bool |
|
32 | + { |
|
33 | + // allow everything |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | } |
@@ -15,28 +15,28 @@ |
||
15 | 15 | */ |
16 | 16 | class BMPString extends PrimitiveString |
17 | 17 | { |
18 | - use UniversalClass; |
|
18 | + use UniversalClass; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Constructor. |
|
22 | - * |
|
23 | - * @param string $string |
|
24 | - */ |
|
25 | - public function __construct(string $string) |
|
26 | - { |
|
27 | - $this->_typeTag = self::TYPE_BMP_STRING; |
|
28 | - parent::__construct($string); |
|
29 | - } |
|
20 | + /** |
|
21 | + * Constructor. |
|
22 | + * |
|
23 | + * @param string $string |
|
24 | + */ |
|
25 | + public function __construct(string $string) |
|
26 | + { |
|
27 | + $this->_typeTag = self::TYPE_BMP_STRING; |
|
28 | + parent::__construct($string); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - protected function _validateString(string $string): bool |
|
35 | - { |
|
36 | - // UCS-2 has fixed with of 2 octets (16 bits) |
|
37 | - if (0 !== strlen($string) % 2) { |
|
38 | - return false; |
|
39 | - } |
|
40 | - return true; |
|
41 | - } |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + protected function _validateString(string $string): bool |
|
35 | + { |
|
36 | + // UCS-2 has fixed with of 2 octets (16 bits) |
|
37 | + if (0 !== strlen($string) % 2) { |
|
38 | + return false; |
|
39 | + } |
|
40 | + return true; |
|
41 | + } |
|
42 | 42 | } |
@@ -13,36 +13,36 @@ |
||
13 | 13 | */ |
14 | 14 | class RelativeOID extends ObjectIdentifier |
15 | 15 | { |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param string $oid OID in dotted format |
|
20 | - */ |
|
21 | - public function __construct(string $oid) |
|
22 | - { |
|
23 | - $this->_oid = $oid; |
|
24 | - $this->_subids = self::_explodeDottedOID($oid); |
|
25 | - $this->_typeTag = self::TYPE_RELATIVE_OID; |
|
26 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param string $oid OID in dotted format |
|
20 | + */ |
|
21 | + public function __construct(string $oid) |
|
22 | + { |
|
23 | + $this->_oid = $oid; |
|
24 | + $this->_subids = self::_explodeDottedOID($oid); |
|
25 | + $this->_typeTag = self::TYPE_RELATIVE_OID; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _encodedContentDER(): string |
|
32 | - { |
|
33 | - return self::_encodeSubIDs(...$this->_subids); |
|
34 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _encodedContentDER(): string |
|
32 | + { |
|
33 | + return self::_encodeSubIDs(...$this->_subids); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * {@inheritdoc} |
|
38 | - */ |
|
39 | - protected static function _decodeFromDER(Identifier $identifier, |
|
40 | - string $data, int &$offset): ElementBase |
|
41 | - { |
|
42 | - $idx = $offset; |
|
43 | - $len = Length::expectFromDER($data, $idx)->intLength(); |
|
44 | - $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
45 | - $offset = $idx + $len; |
|
46 | - return new self(self::_implodeSubIDs(...$subids)); |
|
47 | - } |
|
36 | + /** |
|
37 | + * {@inheritdoc} |
|
38 | + */ |
|
39 | + protected static function _decodeFromDER(Identifier $identifier, |
|
40 | + string $data, int &$offset): ElementBase |
|
41 | + { |
|
42 | + $idx = $offset; |
|
43 | + $len = Length::expectFromDER($data, $idx)->intLength(); |
|
44 | + $subids = self::_decodeSubIDs(substr($data, $idx, $len)); |
|
45 | + $offset = $idx + $len; |
|
46 | + return new self(self::_implodeSubIDs(...$subids)); |
|
47 | + } |
|
48 | 48 | } |
@@ -12,25 +12,25 @@ |
||
12 | 12 | */ |
13 | 13 | class GraphicString extends PrimitiveString |
14 | 14 | { |
15 | - use UniversalClass; |
|
15 | + use UniversalClass; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Constructor. |
|
19 | - * |
|
20 | - * @param string $string |
|
21 | - */ |
|
22 | - public function __construct(string $string) |
|
23 | - { |
|
24 | - $this->_typeTag = self::TYPE_GRAPHIC_STRING; |
|
25 | - parent::__construct($string); |
|
26 | - } |
|
17 | + /** |
|
18 | + * Constructor. |
|
19 | + * |
|
20 | + * @param string $string |
|
21 | + */ |
|
22 | + public function __construct(string $string) |
|
23 | + { |
|
24 | + $this->_typeTag = self::TYPE_GRAPHIC_STRING; |
|
25 | + parent::__construct($string); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - protected function _validateString(string $string): bool |
|
32 | - { |
|
33 | - // allow everything |
|
34 | - return true; |
|
35 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + protected function _validateString(string $string): bool |
|
32 | + { |
|
33 | + // allow everything |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | } |
@@ -9,13 +9,13 @@ |
||
9 | 9 | */ |
10 | 10 | trait PrimitiveType |
11 | 11 | { |
12 | - /** |
|
13 | - * @see \Sop\ASN1\Feature\ElementBase::isConstructed() |
|
14 | - * |
|
15 | - * @return bool |
|
16 | - */ |
|
17 | - public function isConstructed(): bool |
|
18 | - { |
|
19 | - return false; |
|
20 | - } |
|
12 | + /** |
|
13 | + * @see \Sop\ASN1\Feature\ElementBase::isConstructed() |
|
14 | + * |
|
15 | + * @return bool |
|
16 | + */ |
|
17 | + public function isConstructed(): bool |
|
18 | + { |
|
19 | + return false; |
|
20 | + } |
|
21 | 21 | } |
@@ -14,79 +14,79 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class TaggedType extends Element |
16 | 16 | { |
17 | - /** |
|
18 | - * Check whether element supports explicit tagging. |
|
19 | - * |
|
20 | - * @param null|int $expectedTag Optional outer tag expectation |
|
21 | - * |
|
22 | - * @throws \UnexpectedValueException If expectation fails |
|
23 | - * |
|
24 | - * @return ExplicitTagging |
|
25 | - */ |
|
26 | - public function expectExplicit(?int $expectedTag = null): ExplicitTagging |
|
27 | - { |
|
28 | - $el = $this; |
|
29 | - if (!$el instanceof ExplicitTagging) { |
|
30 | - throw new \UnexpectedValueException( |
|
31 | - "Element doesn't implement explicit tagging."); |
|
32 | - } |
|
33 | - if (isset($expectedTag)) { |
|
34 | - $el->expectTagged($expectedTag); |
|
35 | - } |
|
36 | - return $el; |
|
37 | - } |
|
17 | + /** |
|
18 | + * Check whether element supports explicit tagging. |
|
19 | + * |
|
20 | + * @param null|int $expectedTag Optional outer tag expectation |
|
21 | + * |
|
22 | + * @throws \UnexpectedValueException If expectation fails |
|
23 | + * |
|
24 | + * @return ExplicitTagging |
|
25 | + */ |
|
26 | + public function expectExplicit(?int $expectedTag = null): ExplicitTagging |
|
27 | + { |
|
28 | + $el = $this; |
|
29 | + if (!$el instanceof ExplicitTagging) { |
|
30 | + throw new \UnexpectedValueException( |
|
31 | + "Element doesn't implement explicit tagging."); |
|
32 | + } |
|
33 | + if (isset($expectedTag)) { |
|
34 | + $el->expectTagged($expectedTag); |
|
35 | + } |
|
36 | + return $el; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Get the wrapped inner element employing explicit tagging. |
|
41 | - * |
|
42 | - * @param null|int $expectedTag Optional outer tag expectation |
|
43 | - * |
|
44 | - * @throws \UnexpectedValueException If expectation fails |
|
45 | - * |
|
46 | - * @return UnspecifiedType |
|
47 | - */ |
|
48 | - public function asExplicit(?int $expectedTag = null): UnspecifiedType |
|
49 | - { |
|
50 | - return $this->expectExplicit($expectedTag)->explicit(); |
|
51 | - } |
|
39 | + /** |
|
40 | + * Get the wrapped inner element employing explicit tagging. |
|
41 | + * |
|
42 | + * @param null|int $expectedTag Optional outer tag expectation |
|
43 | + * |
|
44 | + * @throws \UnexpectedValueException If expectation fails |
|
45 | + * |
|
46 | + * @return UnspecifiedType |
|
47 | + */ |
|
48 | + public function asExplicit(?int $expectedTag = null): UnspecifiedType |
|
49 | + { |
|
50 | + return $this->expectExplicit($expectedTag)->explicit(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Check whether element supports implicit tagging. |
|
55 | - * |
|
56 | - * @param null|int $expectedTag Optional outer tag expectation |
|
57 | - * |
|
58 | - * @throws \UnexpectedValueException If expectation fails |
|
59 | - * |
|
60 | - * @return ImplicitTagging |
|
61 | - */ |
|
62 | - public function expectImplicit(?int $expectedTag = null): ImplicitTagging |
|
63 | - { |
|
64 | - $el = $this; |
|
65 | - if (!$el instanceof ImplicitTagging) { |
|
66 | - throw new \UnexpectedValueException( |
|
67 | - "Element doesn't implement implicit tagging."); |
|
68 | - } |
|
69 | - if (isset($expectedTag)) { |
|
70 | - $el->expectTagged($expectedTag); |
|
71 | - } |
|
72 | - return $el; |
|
73 | - } |
|
53 | + /** |
|
54 | + * Check whether element supports implicit tagging. |
|
55 | + * |
|
56 | + * @param null|int $expectedTag Optional outer tag expectation |
|
57 | + * |
|
58 | + * @throws \UnexpectedValueException If expectation fails |
|
59 | + * |
|
60 | + * @return ImplicitTagging |
|
61 | + */ |
|
62 | + public function expectImplicit(?int $expectedTag = null): ImplicitTagging |
|
63 | + { |
|
64 | + $el = $this; |
|
65 | + if (!$el instanceof ImplicitTagging) { |
|
66 | + throw new \UnexpectedValueException( |
|
67 | + "Element doesn't implement implicit tagging."); |
|
68 | + } |
|
69 | + if (isset($expectedTag)) { |
|
70 | + $el->expectTagged($expectedTag); |
|
71 | + } |
|
72 | + return $el; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Get the wrapped inner element employing implicit tagging. |
|
77 | - * |
|
78 | - * @param int $tag Type tag of the inner element |
|
79 | - * @param null|int $expectedTag Optional outer tag expectation |
|
80 | - * @param int $expectedClass Optional inner type class expectation |
|
81 | - * |
|
82 | - * @throws \UnexpectedValueException If expectation fails |
|
83 | - * |
|
84 | - * @return UnspecifiedType |
|
85 | - */ |
|
86 | - public function asImplicit(int $tag, ?int $expectedTag = null, |
|
87 | - int $expectedClass = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
88 | - { |
|
89 | - return $this->expectImplicit($expectedTag)->implicit($tag, |
|
90 | - $expectedClass); |
|
91 | - } |
|
75 | + /** |
|
76 | + * Get the wrapped inner element employing implicit tagging. |
|
77 | + * |
|
78 | + * @param int $tag Type tag of the inner element |
|
79 | + * @param null|int $expectedTag Optional outer tag expectation |
|
80 | + * @param int $expectedClass Optional inner type class expectation |
|
81 | + * |
|
82 | + * @throws \UnexpectedValueException If expectation fails |
|
83 | + * |
|
84 | + * @return UnspecifiedType |
|
85 | + */ |
|
86 | + public function asImplicit(int $tag, ?int $expectedTag = null, |
|
87 | + int $expectedClass = Identifier::CLASS_UNIVERSAL): UnspecifiedType |
|
88 | + { |
|
89 | + return $this->expectImplicit($expectedTag)->implicit($tag, |
|
90 | + $expectedClass); |
|
91 | + } |
|
92 | 92 | } |
@@ -11,50 +11,50 @@ |
||
11 | 11 | */ |
12 | 12 | abstract class StringType extends Element |
13 | 13 | { |
14 | - /** |
|
15 | - * String value. |
|
16 | - * |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - protected $_string; |
|
14 | + /** |
|
15 | + * String value. |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + protected $_string; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Constructor. |
|
23 | - * |
|
24 | - * @param string $string |
|
25 | - * |
|
26 | - * @throws \InvalidArgumentException |
|
27 | - */ |
|
28 | - public function __construct(string $string) |
|
29 | - { |
|
30 | - if (!$this->_validateString($string)) { |
|
31 | - throw new \InvalidArgumentException( |
|
32 | - sprintf('Not a valid %s string.', |
|
33 | - self::tagToName($this->_typeTag))); |
|
34 | - } |
|
35 | - $this->_string = $string; |
|
36 | - } |
|
21 | + /** |
|
22 | + * Constructor. |
|
23 | + * |
|
24 | + * @param string $string |
|
25 | + * |
|
26 | + * @throws \InvalidArgumentException |
|
27 | + */ |
|
28 | + public function __construct(string $string) |
|
29 | + { |
|
30 | + if (!$this->_validateString($string)) { |
|
31 | + throw new \InvalidArgumentException( |
|
32 | + sprintf('Not a valid %s string.', |
|
33 | + self::tagToName($this->_typeTag))); |
|
34 | + } |
|
35 | + $this->_string = $string; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the string value. |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function string(): string |
|
44 | - { |
|
45 | - return $this->_string; |
|
46 | - } |
|
38 | + /** |
|
39 | + * Get the string value. |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function string(): string |
|
44 | + { |
|
45 | + return $this->_string; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Check whether string is valid for the concrete type. |
|
50 | - * |
|
51 | - * @param string $string |
|
52 | - * |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - protected function _validateString(string $string): bool |
|
56 | - { |
|
57 | - // Override in derived classes |
|
58 | - return true; |
|
59 | - } |
|
48 | + /** |
|
49 | + * Check whether string is valid for the concrete type. |
|
50 | + * |
|
51 | + * @param string $string |
|
52 | + * |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + protected function _validateString(string $string): bool |
|
56 | + { |
|
57 | + // Override in derived classes |
|
58 | + return true; |
|
59 | + } |
|
60 | 60 | } |
@@ -14,76 +14,76 @@ |
||
14 | 14 | */ |
15 | 15 | class DERData extends Element |
16 | 16 | { |
17 | - /** |
|
18 | - * DER encoded data. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_der; |
|
17 | + /** |
|
18 | + * DER encoded data. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_der; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Identifier of the underlying type. |
|
26 | - * |
|
27 | - * @var Identifier |
|
28 | - */ |
|
29 | - protected $_identifier; |
|
24 | + /** |
|
25 | + * Identifier of the underlying type. |
|
26 | + * |
|
27 | + * @var Identifier |
|
28 | + */ |
|
29 | + protected $_identifier; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Offset to the content in DER data. |
|
33 | - * |
|
34 | - * @var int |
|
35 | - */ |
|
36 | - protected $_contentOffset = 0; |
|
31 | + /** |
|
32 | + * Offset to the content in DER data. |
|
33 | + * |
|
34 | + * @var int |
|
35 | + */ |
|
36 | + protected $_contentOffset = 0; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor. |
|
40 | - * |
|
41 | - * @param string $data DER encoded data |
|
42 | - * |
|
43 | - * @throws \Sop\ASN1\Exception\DecodeException If data does not adhere to DER |
|
44 | - */ |
|
45 | - public function __construct(string $data) |
|
46 | - { |
|
47 | - $this->_identifier = Identifier::fromDER($data, $this->_contentOffset); |
|
48 | - // check that length encoding is valid |
|
49 | - Length::expectFromDER($data, $this->_contentOffset); |
|
50 | - $this->_der = $data; |
|
51 | - $this->_typeTag = $this->_identifier->intTag(); |
|
52 | - } |
|
38 | + /** |
|
39 | + * Constructor. |
|
40 | + * |
|
41 | + * @param string $data DER encoded data |
|
42 | + * |
|
43 | + * @throws \Sop\ASN1\Exception\DecodeException If data does not adhere to DER |
|
44 | + */ |
|
45 | + public function __construct(string $data) |
|
46 | + { |
|
47 | + $this->_identifier = Identifier::fromDER($data, $this->_contentOffset); |
|
48 | + // check that length encoding is valid |
|
49 | + Length::expectFromDER($data, $this->_contentOffset); |
|
50 | + $this->_der = $data; |
|
51 | + $this->_typeTag = $this->_identifier->intTag(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritdoc} |
|
56 | - */ |
|
57 | - public function typeClass(): int |
|
58 | - { |
|
59 | - return $this->_identifier->typeClass(); |
|
60 | - } |
|
54 | + /** |
|
55 | + * {@inheritdoc} |
|
56 | + */ |
|
57 | + public function typeClass(): int |
|
58 | + { |
|
59 | + return $this->_identifier->typeClass(); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * {@inheritdoc} |
|
64 | - */ |
|
65 | - public function isConstructed(): bool |
|
66 | - { |
|
67 | - return $this->_identifier->isConstructed(); |
|
68 | - } |
|
62 | + /** |
|
63 | + * {@inheritdoc} |
|
64 | + */ |
|
65 | + public function isConstructed(): bool |
|
66 | + { |
|
67 | + return $this->_identifier->isConstructed(); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * {@inheritdoc} |
|
72 | - */ |
|
73 | - public function toDER(): string |
|
74 | - { |
|
75 | - return $this->_der; |
|
76 | - } |
|
70 | + /** |
|
71 | + * {@inheritdoc} |
|
72 | + */ |
|
73 | + public function toDER(): string |
|
74 | + { |
|
75 | + return $this->_der; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * {@inheritdoc} |
|
80 | - */ |
|
81 | - protected function _encodedContentDER(): string |
|
82 | - { |
|
83 | - // if there's no content payload |
|
84 | - if (strlen($this->_der) == $this->_contentOffset) { |
|
85 | - return ''; |
|
86 | - } |
|
87 | - return substr($this->_der, $this->_contentOffset); |
|
88 | - } |
|
78 | + /** |
|
79 | + * {@inheritdoc} |
|
80 | + */ |
|
81 | + protected function _encodedContentDER(): string |
|
82 | + { |
|
83 | + // if there's no content payload |
|
84 | + if (strlen($this->_der) == $this->_contentOffset) { |
|
85 | + return ''; |
|
86 | + } |
|
87 | + return substr($this->_der, $this->_contentOffset); |
|
88 | + } |
|
89 | 89 | } |
@@ -6,107 +6,107 @@ |
||
6 | 6 | |
7 | 7 | class BigInt |
8 | 8 | { |
9 | - /** |
|
10 | - * Number as a base10 integer string. |
|
11 | - * |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - private $_num; |
|
9 | + /** |
|
10 | + * Number as a base10 integer string. |
|
11 | + * |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + private $_num; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Number as an integer type. |
|
18 | - * |
|
19 | - * @internal Lazily initialized |
|
20 | - * |
|
21 | - * @var null|int |
|
22 | - */ |
|
23 | - private $_intNum; |
|
16 | + /** |
|
17 | + * Number as an integer type. |
|
18 | + * |
|
19 | + * @internal Lazily initialized |
|
20 | + * |
|
21 | + * @var null|int |
|
22 | + */ |
|
23 | + private $_intNum; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param int|string $num |
|
29 | - */ |
|
30 | - public function __construct($num) |
|
31 | - { |
|
32 | - $this->_num = strval($num); |
|
33 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param int|string $num |
|
29 | + */ |
|
30 | + public function __construct($num) |
|
31 | + { |
|
32 | + $this->_num = strval($num); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function __toString() |
|
39 | - { |
|
40 | - return $this->base10(); |
|
41 | - } |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function __toString() |
|
39 | + { |
|
40 | + return $this->base10(); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Get the number as a base10 integer string. |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function base10(): string |
|
49 | - { |
|
50 | - return $this->_num; |
|
51 | - } |
|
43 | + /** |
|
44 | + * Get the number as a base10 integer string. |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function base10(): string |
|
49 | + { |
|
50 | + return $this->_num; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get the number as an integer. |
|
55 | - * |
|
56 | - * @throws \RuntimeException If number overflows integer size |
|
57 | - * |
|
58 | - * @return int |
|
59 | - */ |
|
60 | - public function intVal(): int |
|
61 | - { |
|
62 | - if (!isset($this->_intNum)) { |
|
63 | - $num = gmp_init($this->_num, 10); |
|
64 | - if (gmp_cmp($num, $this->_intMaxGmp()) > 0) { |
|
65 | - throw new \RuntimeException('Integer overflow.'); |
|
66 | - } |
|
67 | - if (gmp_cmp($num, $this->_intMinGmp()) < 0) { |
|
68 | - throw new \RuntimeException('Integer underflow.'); |
|
69 | - } |
|
70 | - $this->_intNum = gmp_intval($num); |
|
71 | - } |
|
72 | - return $this->_intNum; |
|
73 | - } |
|
53 | + /** |
|
54 | + * Get the number as an integer. |
|
55 | + * |
|
56 | + * @throws \RuntimeException If number overflows integer size |
|
57 | + * |
|
58 | + * @return int |
|
59 | + */ |
|
60 | + public function intVal(): int |
|
61 | + { |
|
62 | + if (!isset($this->_intNum)) { |
|
63 | + $num = gmp_init($this->_num, 10); |
|
64 | + if (gmp_cmp($num, $this->_intMaxGmp()) > 0) { |
|
65 | + throw new \RuntimeException('Integer overflow.'); |
|
66 | + } |
|
67 | + if (gmp_cmp($num, $this->_intMinGmp()) < 0) { |
|
68 | + throw new \RuntimeException('Integer underflow.'); |
|
69 | + } |
|
70 | + $this->_intNum = gmp_intval($num); |
|
71 | + } |
|
72 | + return $this->_intNum; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Get the number as a GMP object. |
|
77 | - * |
|
78 | - * @return \GMP |
|
79 | - */ |
|
80 | - public function gmpObj(): \GMP |
|
81 | - { |
|
82 | - return gmp_init($this->_num, 10); |
|
83 | - } |
|
75 | + /** |
|
76 | + * Get the number as a GMP object. |
|
77 | + * |
|
78 | + * @return \GMP |
|
79 | + */ |
|
80 | + public function gmpObj(): \GMP |
|
81 | + { |
|
82 | + return gmp_init($this->_num, 10); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Get the maximum integer value. |
|
87 | - * |
|
88 | - * @return \GMP |
|
89 | - */ |
|
90 | - private function _intMaxGmp(): \GMP |
|
91 | - { |
|
92 | - static $gmp; |
|
93 | - if (!isset($gmp)) { |
|
94 | - $gmp = gmp_init(PHP_INT_MAX, 10); |
|
95 | - } |
|
96 | - return $gmp; |
|
97 | - } |
|
85 | + /** |
|
86 | + * Get the maximum integer value. |
|
87 | + * |
|
88 | + * @return \GMP |
|
89 | + */ |
|
90 | + private function _intMaxGmp(): \GMP |
|
91 | + { |
|
92 | + static $gmp; |
|
93 | + if (!isset($gmp)) { |
|
94 | + $gmp = gmp_init(PHP_INT_MAX, 10); |
|
95 | + } |
|
96 | + return $gmp; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get the minimum integer value. |
|
101 | - * |
|
102 | - * @return \GMP |
|
103 | - */ |
|
104 | - private function _intMinGmp(): \GMP |
|
105 | - { |
|
106 | - static $gmp; |
|
107 | - if (!isset($gmp)) { |
|
108 | - $gmp = gmp_init(PHP_INT_MIN, 10); |
|
109 | - } |
|
110 | - return $gmp; |
|
111 | - } |
|
99 | + /** |
|
100 | + * Get the minimum integer value. |
|
101 | + * |
|
102 | + * @return \GMP |
|
103 | + */ |
|
104 | + private function _intMinGmp(): \GMP |
|
105 | + { |
|
106 | + static $gmp; |
|
107 | + if (!isset($gmp)) { |
|
108 | + $gmp = gmp_init(PHP_INT_MIN, 10); |
|
109 | + } |
|
110 | + return $gmp; |
|
111 | + } |
|
112 | 112 | } |