-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Open
Labels
Description
Description
Ulid::isValid(string): bool
is at the moment very strict about which text representation of the Ulid is valid and which not.
I would expect that this would work:
$ulid = new Ulid();
$string = $ulid->toRfc4122();
Ulid::isValid($string) // I would expect this to be true
The workarround we are using is to try to test if a string is a valid Ulid:
function isUlidTextRepresentation(string $string): bool
{
try {
Ulid::fromString($string);
} catch (\InvalidArgumentException) {
return false;
}
return true;
}
I think it would be possible to either change the Ulid::isValid method with the above implementation, or have another static function of the Ulid class to do something similar to this, to not change the behaviour of Ulid::isValid()
. I could create a PR for either option....
Example
$ulid = new Ulid();
$string = $ulid->toRfc4122();
Ulid::isValid($string) // This returns true