refactor(console, id, config): Dialog mode in Console, consolidated id modul, added config support for ini directives
This commit is contained in:
56
src/Framework/Id/Ulid/StringConverter.php
Normal file
56
src/Framework/Id/Ulid/StringConverter.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Id\Ulid;
|
||||
|
||||
use App\Framework\Core\Encoding\Base32Alphabet;
|
||||
use App\Framework\Core\Encoding\Base32Encoder;
|
||||
|
||||
/**
|
||||
* ULID String Converter using Crockford's Base32 alphabet
|
||||
*
|
||||
* Migrated to use the framework's Base32Encoder with Crockford alphabet
|
||||
* for consistency and better maintainability.
|
||||
*/
|
||||
final readonly class StringConverter
|
||||
{
|
||||
/**
|
||||
* Encodes a binary string into a Base32 encoded string using Crockford's alphabet
|
||||
*
|
||||
* @param string $binary The binary string to be encoded.
|
||||
* @return string The Base32 encoded string.
|
||||
*/
|
||||
public function encodeBase32(string $binary): string
|
||||
{
|
||||
return Base32Encoder::encodeCrockford($binary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a Base32-encoded string into its binary representation
|
||||
*
|
||||
* @param string $base32 The Base32-encoded string to decode.
|
||||
* @return string The binary representation of the decoded string.
|
||||
* @throws \InvalidArgumentException If the provided string contains invalid Base32 characters.
|
||||
*/
|
||||
public function decodeBase32(string $base32): string
|
||||
{
|
||||
return Base32Encoder::decodeCrockford($base32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if string is valid Crockford Base32
|
||||
*/
|
||||
public function isValidBase32(string $base32): bool
|
||||
{
|
||||
return Base32Alphabet::CROCKFORD->isValidEncoded($base32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Crockford Base32 alphabet used by ULID
|
||||
*/
|
||||
public function getAlphabet(): string
|
||||
{
|
||||
return Base32Alphabet::CROCKFORD->getAlphabet();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user