File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 2727 },
2828 "require" : {
2929 "php" : " ^8.1" ,
30+ "ext-bcmath" : " *" ,
3031 "ext-date" : " *" ,
3132 "ext-dom" : " *" ,
3233 "ext-filter" : " *" ,
Original file line number Diff line number Diff line change 55namespace SimpleSAML \XML \Type ;
66
77use SimpleSAML \XML \Assert \Assert ;
8- use SimpleSAML \XML \Exception \SchemaViolationException ;
8+ use SimpleSAML \XML \Exception \{RuntimeException , SchemaViolationException };
9+
10+ use function bccomp ;
11+ use function intval ;
12+ use function strval ;
913
1014/**
1115 * @package simplesaml/xml-common
@@ -27,4 +31,33 @@ protected function validateValue(string $value): void
2731 {
2832 Assert::validInteger ($ this ->sanitizeValue ($ value ), SchemaViolationException::class);
2933 }
34+
35+
36+ /**
37+ * Convert from integer
38+ *
39+ * @param int $value
40+ * @return static
41+ */
42+ public static function fromInteger (int $ value ): static
43+ {
44+ return new static (strval ($ value ));
45+ }
46+
47+
48+ /**
49+ * Convert to integer
50+ *
51+ * @return int
52+ */
53+ public function toInteger (): int
54+ {
55+ $ value = $ this ->getValue ();
56+
57+ if (bccomp ($ value , strval (PHP_INT_MAX )) === 1 ) {
58+ throw new RuntimeException ("Cannot convert to integer: out of bounds. " );
59+ }
60+
61+ return intval ($ value );
62+ }
3063}
You can’t perform that action at this time.
0 commit comments