tiny-blocks / encoder
Encoder and decoder for arbitrary data.
Installs: 30 517
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.3
- ext-bcmath: *
Requires (Dev)
- infection/infection: ^0.29
- phpmd/phpmd: ^2.15
- phpstan/phpstan: ^1
- phpunit/phpunit: ^11
- squizlabs/php_codesniffer: ^3.11
Suggests
- ext-bcmath: Enables the extension which is an interface to the GNU implementation as a Basic Calculator utility library.
README
Overview
Encoder and decoder for arbitrary data.
Installation
composer require tiny-blocks/encoder
How to use
The library provides concrete implementations of the Encoder
interface, enabling encoding and decoding of data into
specific formats like Base62.
Using Base62
To encode a value into Base62 format:
$encoder = Base62::from(value: 'Hello world!'); $encoded = $encoder->encode(); # Output: T8dgcjRGuYUueWht
To decode a Base62-encoded value back to its original form:
$encoder = Base62::from(value: 'T8dgcjRGuYUueWht'); $decoded = $encoder->decode(); # Output: Hello world!
If you attempt to decode an invalid Base62 value, an InvalidDecoding
exception will be thrown:
try { $encoder = Base62::from(value: 'invalid_value'); $decoded = $encoder->decode(); } catch (InvalidDecoding $exception) { echo $exception->getMessage(); # Output: The value <invalid_value> could not be decoded. }
License
Encoder is licensed under MIT.
Contributing
Please follow the contributing guidelines to contribute to the project.