Description
With the current AbstractUid
contract we can output different "formats" by calling dedicated methods: toBase58()
, toBase32()
, toRfc4122()
and toBinary()
. However, when we want to convert back a string uid to its object we can only use the fromString()
method (that method handle all the possible formats one by one).
I think it would be more convenient to add dedicated methods for the "from" action too. You could use them when you know the input format and want to restrict it. Currently, in my code, I have to do:
if (22 !== strlen($base58Ulid)) {
throw new \InvalidArgumentException();
}
before any call to Ulid::fromString($base58Ulid)
because I do not want to support (accidentally) the case where $base58Ulid
would actually contain the rfc 4122 version for example. I would prefer to use Ulid::fromBase58($base58Ulid)
and let Symfony handle the validation 🤷♂️ Does that make sense?