Skip to content

[Uid] Add fromBase58(), fromBase32(), fromRfc4122() and fromBinary() methods #39801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fancyweb opened this issue Jan 12, 2021 · 0 comments
Closed
Labels

Comments

@fancyweb
Copy link
Contributor

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?

@carsonbot carsonbot added the Uid label Jan 12, 2021
nicolas-grekas added a commit that referenced this issue Jan 20, 2021
…d fromBinary() methods (fancyweb)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[Uid] Add fromBase58(), fromBase32(), fromRfc4122() and fromBinary() methods

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | #39801
| License       | MIT
| Doc PR        | -

Commits
-------

c01ec7d [Uid] Add fromBase58(), fromBase32(), fromRfc4122() and fromBinary()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants