1 | <?php |
||
10 | class Base64 |
||
11 | { |
||
12 | /** |
||
13 | * Encode a string using base64url variant. |
||
14 | * |
||
15 | * @link https://en.wikipedia.org/wiki/Base64#URL_applications |
||
16 | * @param string $data |
||
17 | * @return string |
||
18 | */ |
||
19 | 170 | public static function urlEncode(string $data): string |
|
23 | |||
24 | /** |
||
25 | * Decode a string using base64url variant. |
||
26 | * |
||
27 | * @link https://en.wikipedia.org/wiki/Base64#URL_applications |
||
28 | * @param string $data |
||
29 | * @throws \UnexpectedValueException |
||
30 | * @return string |
||
31 | */ |
||
32 | 130 | public static function urlDecode(string $data): string |
|
50 | |||
51 | /** |
||
52 | * Check whether string is validly base64url encoded. |
||
53 | * |
||
54 | * @link https://en.wikipedia.org/wiki/Base64#URL_applications |
||
55 | * @param string $data |
||
56 | * @return bool |
||
57 | */ |
||
58 | 128 | public static function isValidURLEncoding(string $data): bool |
|
62 | |||
63 | /** |
||
64 | * Encode a string in base64. |
||
65 | * |
||
66 | * @link https://tools.ietf.org/html/rfc4648#section-4 |
||
67 | * @param string $data |
||
68 | * @throws \RuntimeException If encoding fails |
||
69 | * @return string |
||
70 | */ |
||
71 | 173 | public static function encode(string $data): string |
|
81 | |||
82 | /** |
||
83 | * Decode a string from base64 encoding. |
||
84 | * |
||
85 | * @link https://tools.ietf.org/html/rfc4648#section-4 |
||
86 | * @param string $data |
||
87 | * @throws \RuntimeException If decoding fails |
||
88 | * @return string |
||
89 | */ |
||
90 | 131 | public static function decode(string $data): string |
|
100 | |||
101 | /** |
||
102 | * Check whether string is validly base64 encoded. |
||
103 | * |
||
104 | * @link https://tools.ietf.org/html/rfc4648#section-4 |
||
105 | * @param string $data |
||
106 | * @return bool |
||
107 | */ |
||
108 | 6 | public static function isValid(string $data): bool |
|
112 | } |
||
113 |