codekandis / base64-codec
`codekandis/base64-codec` is a library providing a codec to encode into and decode from Base64 in an object oriented way.
2.1.0
2021-01-17 23:48 UTC
Requires
- php: ^7.4
- codekandis/constants-classes-translator: ^1
Requires (Dev)
- codekandis/phpunit: ^3
- roave/security-advisories: dev-master
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
With the Base64 codec you will be able to encode into and decode from Base64 data in an object oriented way. It wraps PHP's functions base64_encode() and base64_decode().
Index
Installation
Install the latest version with
$ composer require codekandis/base64-codec
How to use
Encoding values
The following examples show how to encode a value.
$value = '8ÇÂ<Ç<ï¯ñ×78B>ïAË¡4Wïc§ÿPîXø4\Êá¡t7?/SµÚ²·x}0¤¯ç»M'; ( new Base64Encoder() ) ->encodeToStandard( $value ); /** * OMOHw4I8w4c8w6/Cr8Oxw5c3OEI+w69Bw4vCoTRXw69jwqfDv1DDrljDuDRcw4rDocKhdDc/L1PCtcOawrLCt3h9MMKkwq/Dp8K7TQ== */ ( new Base64Encoder() ) ->encodeToUriSafe( $value ); /** * OMOHw4I8w4c8w6_Cr8Oxw5c3OEI-w69Bw4vCoTRXw69jwqfDv1DDrljDuDRcw4rDocKhdDc_L1PCtcOawrLCt3h9MMKkwq_Dp8K7TQ */
Decoding values
The following examples show how to decode a value.
$standardBase64Value = 'OMOHw4I8w4c8w6/Cr8Oxw5c3OEI+w69Bw4vCoTRXw69jwqfDv1DDrljDuDRcw4rDocKhdDc/L1PCtcOawrLCt3h9MMKkwq/Dp8K7TQ=='; ( new Base64Decoder() ) ->decodeFromStandard( $standardBase64Value ); /** * 8ÇÂ<Ç<ï¯ñ×78B>ïAË¡4Wïc§ÿPîXø4\Êá¡t7?/SµÚ²·x}0¤¯ç»M */ $uriSafeBase64Value = 'OMOHw4I8w4c8w6_Cr8Oxw5c3OEI-w69Bw4vCoTRXw69jwqfDv1DDrljDuDRcw4rDocKhdDc_L1PCtcOawrLCt3h9MMKkwq_Dp8K7TQ'; ( new Base64Decoder() ) ->decodeFromUriSafe( $uriSafeBase64Value ); /** * 8ÇÂ<Ç<ï¯ñ×78B>ïAË¡4Wïc§ÿPîXø4\Êá¡t7?/SµÚ²·x}0¤¯ç»M */
Differences to PHP's Base64 functions
base64_decode() accepts an additional argument $strict to specify if it's forced to decode into an associative array. This argument is omitted in the Base64DecoderInterface while it's intended to always decode in strict mode.