This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Nicolas Grekas e2f1c46734 feature #39883 [Uid] Add Generate and Inspect commands (fancyweb)
This PR was merged into the 5.3-dev branch.

Discussion
----------

[Uid] Add Generate and Inspect commands

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| 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
```yaml
# services.yaml
services:
    Symfony\Component\Uid\Command\GenerateUlidCommand: ~
    Symfony\Component\Uid\Command\GenerateUuidCommand: ~
    Symfony\Component\Uid\Command\InspectUlidCommand: ~
    Symfony\Component\Uid\Command\InspectUuidCommand: ~
```

## PHP
```php
<?php

// services.php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\Uid\Command\GenerateUlidCommand;
use Symfony\Component\Uid\Command\GenerateUuidCommand;
use Symfony\Component\Uid\Command\InspectUlidCommand;
use Symfony\Component\Uid\Command\InspectUuidCommand;

return static function (ContainerConfigurator $configurator): void {
    $services = $configurator->services()
        ->defaults()
        ->autowire()
        ->autoconfigure();

    $services
        ->set(GenerateUlidCommand::class)
        ->set(GenerateUuidCommand::class)
        ->set(InspectUlidCommand::class)
        ->set(InspectUuidCommand::class);
};
```

Commits
-------

223421b6ca [Uid] Add Generate and Inspect commands
2021-02-25 17:25:32 +01:00
.github Add default issue templates back 2021-02-24 14:32:19 +01:00
src/Symfony feature #39883 [Uid] Add Generate and Inspect commands (fancyweb) 2021-02-25 17:25:32 +01:00
.appveyor.yml Merge branch '4.4' into 5.2 2021-02-16 11:13:48 +01:00
.editorconfig Update .editorconfig 2018-09-06 16:22:56 +02:00
.gitattributes Don't "replace" mailer bridges in "symfony/symfony" 2021-02-07 16:15:59 +01:00
.gitignore Run the phpunit-bridge from a PR 2019-08-02 17:46:19 +02:00
.php_cs.dist Merge branch '5.1' into 5.2 2021-01-19 22:00:40 +01:00
.travis.yml Merge branch '5.2' into 5.x 2021-02-17 16:27:35 +01:00
CHANGELOG-5.0.md Merge branch '5.0' into 5.1 2020-06-15 13:50:15 +02:00
CHANGELOG-5.1.md Update CHANGELOG for 5.1.10 2020-12-18 14:43:18 +01:00
CHANGELOG-5.2.md Update CHANGELOG for 5.2.3 2021-02-03 05:51:42 +01:00
CODE_OF_CONDUCT.md Added the Code of Conduct file 2018-10-10 03:13:30 -07:00
composer.json [Routing] Construct Route annotations using named arguments 2021-02-24 14:30:32 +01:00
CONTRIBUTING.md Mention the community review guide 2016-12-18 22:02:35 +01:00
CONTRIBUTORS.md Add some information about the username in CONTRIBUTORS 2021-02-09 09:21:20 +01:00
LICENSE Bump license year 2021-01-01 10:24:35 +01:00
link Merge branch '5.1' into 5.2 2020-12-10 20:16:15 +01:00
phpunit Merge branch '4.4' into 5.2 2021-02-11 09:21:20 +01:00
phpunit.xml.dist Merge branch '4.4' into 5.1 2020-11-16 16:58:32 +01:00
README.md Update README.md 2020-12-29 01:17:49 +01:00
UPGRADE-5.0.md Merge branch '4.4' into 5.1 2020-12-10 18:44:54 +01:00
UPGRADE-5.1.md Update UPGRADE-5.1.md 2020-09-07 01:58:27 +02:00
UPGRADE-5.2.md [HttpFoundation] Deprecate BinaryFileResponse::create(). 2020-11-20 16:47:02 +01:00
UPGRADE-5.3.md feature #40266 [Routing] Construct Route annotations using named arguments (derrabus) 2021-02-25 08:31:04 +01:00
UPGRADE-6.0.md [Routing] Construct Route annotations using named arguments 2021-02-24 14:30:32 +01:00

Symfony is a PHP framework for web and console applications and a set of reusable PHP components. Symfony is used by thousands of web applications (including BlaBlaCar.com and Spotify.com) and most of the popular PHP projects (including Drupal and Magento).

Installation

Documentation

Community

Contributing

Symfony is an Open Source, community-driven project with thousands of contributors. Join them contributing code or contributing documentation.

Security Issues

If you discover a security vulnerability within Symfony, please follow our disclosure procedure.

About Us

Symfony development is sponsored by SensioLabs, led by the Symfony Core Team and supported by Symfony contributors.