Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Uid] Add Generate and Inspect commands#39883

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:5.xfromfancyweb:uid-commands
Feb 25, 2021

Conversation

@fancyweb
Copy link
Contributor

@fancywebfancyweb commentedJan 18, 2021
edited
Loading

QA
Branch?5.x
Bug fix?no
New feature?yes
Deprecations?no
Tickets-
LicenseMIT
Doc PR-

After some time using the component, I realized I often needed to quickly generate new ulids or to convert them from one format to another so I thought having those commands would be useful.

Usage

Generate a ULID - outputs N ULID(s) separated by new lines in base 32, base 58 or RFC 4122 format

Generate 1 ULID now

php bin/console ulid:generate

Generate 1 ULID with a specific timestamp

php bin/console ulid:generate --time="2021-02-02 14:00:00"

Generate 2 ULIDs and ouput the RFC4122 format

php bin/console ulid:generate --count=2 --format=rfc4122

Generate a UUID - outputs N UUID(s) separated by new lines in RFC 4122, base 58 or base 32 format

Generate 1 UUID (defaults from the underlying factory)

php bin/console uuid:generate

Generate 1 time-based UUID now

php bin/console uuid:generate --time-based=now

Generate 1 time-based UUID with a specific timestamp

php bin/console uuid:generate --time-based="2021-02-02 14:00:00"

Generate 1 time-based UUID with a specific node

php bin/console uuid:generate --time-based=now --node=fb3502dc-137e-4849-8886-ac90d07f64a7

Generate 1 name-based UUID (there must be a default namespace in the underlying factory)

php bin/console uuid:generate --name-based=foo

Generate 1 name-based UUID with a specific namespace (overrides the default namespace from the underlying factory)

php bin/console uuid:generate --name-based=foo --namespace=fb3502dc-137e-4849-8886-ac90d07f64a7

Generate 1 random-based UUID

php bin/console uuid:generate --random-based

Generate 2 UUIDs and output their base 58 format

php bin/console uuid:generate --count=2 --format=base58

Inspect a ULID - outputs base32, base58 and RFC 4122 formats of a ULID and its humand readable timestamp if it is time-based

php bin/console ulid:inspect 01EWAKBCMWQ2C94EXNN60ZBS0Q
php bin/console ulid:inspect 1BVdfLn3ERmbjYBLCdaaLW
php bin/console ulid:inspect 01771535-b29c-b898-923b-b5a981f5e417

Inspect a UUID - outputs RFC 4122, base 58 and base 32 formats of a UUID and its human readable timestamp

php bin/console uuid:inspect a7613e0a-5986-11eb-a861-2bf05af69e52
php bin/console uuid:inspect MfnmaUvvQ1h8B14vTwt6dX
php bin/console uuid:inspect 57C4Z0MPC627NTGR9BY1DFD7JJ

Register the commands

YAML

# services.yamlservices:Symfony\Component\Uid\Command\GenerateUlidCommand:~Symfony\Component\Uid\Command\GenerateUuidCommand:~Symfony\Component\Uid\Command\InspectUlidCommand:~Symfony\Component\Uid\Command\InspectUuidCommand:~

PHP

<?php// services.phpnamespaceSymfony\Component\DependencyInjection\Loader\Configurator;useSymfony\Component\Uid\Command\GenerateUlidCommand;useSymfony\Component\Uid\Command\GenerateUuidCommand;useSymfony\Component\Uid\Command\InspectUlidCommand;useSymfony\Component\Uid\Command\InspectUuidCommand;returnstaticfunction (ContainerConfigurator$configurator):void {$services =$configurator->services()        ->defaults()        ->autowire()        ->autoconfigure();$services        ->set(GenerateUlidCommand::class)        ->set(GenerateUuidCommand::class)        ->set(InspectUlidCommand::class)        ->set(InspectUuidCommand::class);};

ro0NL reacted with thumbs up emoji
@stof
Copy link
Member

See#36405 for previous discussion about that topic.

@jderussejderusse added this to the5.x milestoneJan 18, 2021
@fabpot
Copy link
Member

Still 👎 for me.

@nicolas-grekas
Copy link
Member

The commands could be provided as a third party bundle.

Alternatively, we could provide them in the source, but not register them as commands, so that ppl could enable them by adding a line in theirservices.yaml file:

services:Symfony\Component\Uid\Command\GenerateUlidCommand:~

This approach could enable us to provide commands without cluttering thelist command by default.

WDYT@fabpot?

@fabpot
Copy link
Member

Sure, if they are hidden by default, no problems for me.

@fancywebfancywebforce-pushed theuid-commands branch 3 times, most recently from7d4b5db tobedc3f5CompareJanuary 19, 2021 12:15
@fancyweb
Copy link
ContributorAuthor

fancyweb commentedJan 19, 2021
edited
Loading

Unfortunately I did not know there was already another PR for that feature in the past. I still think it's an useful feature to offer. I have removed the commands registration in the FWB and fixed the other comments. I also changed the timestamp display to be in milliseconds. I still need to fix the tests.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

some thougths

@maxhelias
Copy link
Contributor

Is it possible to have a format option (rfc, binary..) ?

@fancywebfancywebforce-pushed theuid-commands branch 2 times, most recently from836350b to325d898CompareFebruary 17, 2021 12:56
@fancyweb
Copy link
ContributorAuthor

I pushed a new implementation that leverages the new factories.

@maxhelias I added a --format option to the generate commands.

maxhelias reacted with heart emoji

@fancywebfancywebforce-pushed theuid-commands branch 2 times, most recently fromb9b5b7b to1eff44fCompareFebruary 17, 2021 16:57
@ro0NL
Copy link
Contributor

Sure, if they are hidden by default, no problems for me.

arent we registering them as hidden? being able to default advertisebin/console .. seems reasonable

publicconstNORMALIZATION_FORMAT_RFC_4122 ='rfc_4122';
publicconstNORMALIZATION_FORMAT_BASE58 ='base58';
publicconstNORMALIZATION_FORMAT_BASE32 ='base32';
publicconstNORMALIZATION_FORMAT_RFC4122 ='rfc4122';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

i feel like we should move the consts toAbstractUid

Copy link
Member

@nicolas-grekasnicolas-grekasFeb 23, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why?AbstractUid nor theUid component wouldn't use them anywhere.

Copy link
Contributor

@ro0NLro0NLFeb 23, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

because the formats are leaking now:The ULID output format: base32, base58 or rfc4122

Copy link
Member

@nicolas-grekasnicolas-grekasFeb 23, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think these consts in Serializer are legit.
Then, the duplication in Uid is legit also - these are from different domains.
Also, the commands (on the cli), use inline values.
In the end, these consts in Uid won't serve any purpose for the devs.
They would actually make the public API of the component more complex to me.
I'd prefer not to add them as you might have understood :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

i think both serializer+console are duplicating what could beAbstractUid::toFormat($format)

Copy link
Member

@nicolas-grekasnicolas-grekasFeb 23, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh, then I'd recommend splitting this discussion into a separate PR or issue.

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedFeb 23, 2021
edited
Loading

arent we registering them as hidden?

Nope: we'renot registering them by default, so that we'll ask ppl to opt-in to list them.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Don't miss updating the description of the PR :)

Co-authored-by: Nicolas Grekas <nicolas.grekas@gmail.com>
@nicolas-grekas
Copy link
Member

Thank you@fancyweb.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@jderussejderussejderusse left review comments

@OskarStarkOskarStarkOskarStark left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@derrabusderrabusderrabus approved these changes

@dunglasdunglasAwaiting requested review from dunglas

+1 more reviewer

@ro0NLro0NLro0NL left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

10 participants

@fancyweb@stof@fabpot@nicolas-grekas@maxhelias@ro0NL@jderusse@OskarStark@derrabus@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp