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

Appearance settings

Commit dff069a

Browse filesBrowse files
committed
[Uid] [GenerateUuidCommand] Add predefined namespaces keywords "dns", "url", "oid" and "x500" as valid input for the --namespace option
1 parent 1b93740 commit dff069a
Copy full SHA for dff069a

File tree

3 files changed

+32
-8
lines changed
Filter options

3 files changed

+32
-8
lines changed

‎src/Symfony/Component/Uid/Command/GenerateUuidCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Uid/Command/GenerateUuidCommand.php
+22-7Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function configure(): void
4444
new InputOption('time-based', null, InputOption::VALUE_REQUIRED, 'The timestamp, to generate a time-based UUID: a parsable date/time string'),
4545
new InputOption('node', null, InputOption::VALUE_REQUIRED, 'The UUID whose node part should be used as the node of the generated UUID'),
4646
new InputOption('name-based', null, InputOption::VALUE_REQUIRED, 'The name, to generate a name-based UUID'),
47-
new InputOption('namespace', null, InputOption::VALUE_REQUIRED, 'The UUID to use at the namespace for named-based UUIDs'),
47+
new InputOption('namespace', null, InputOption::VALUE_REQUIRED, 'The UUID to use at the namespace for named-based UUIDs. Predefined namespaces keywords "dns", "url", "oid" and "x500" are accepted'),
4848
new InputOption('random-based', null, InputOption::VALUE_NONE, 'To generate a random-based UUID'),
4949
new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of UUID to generate', 1),
5050
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'The UUID output format: rfc4122, base58 or base32', 'rfc4122'),
@@ -145,12 +145,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
145145

146146
case null !== $name:
147147
if ($namespace) {
148-
try {
149-
$namespace = Uuid::fromString($namespace);
150-
} catch (\InvalidArgumentException $e) {
151-
$io->error(sprintf('Invalid namespace "%s": %s', $namespace, $e->getMessage()));
152-
153-
return 1;
148+
switch ($namespace) {
149+
case 'dns':
150+
$namespace = Uuid::NAMESPACE_DNS;
151+
break;
152+
case 'url':
153+
$namespace = Uuid::NAMESPACE_URL;
154+
break;
155+
case 'oid':
156+
$namespace = Uuid::NAMESPACE_OID;
157+
break;
158+
case 'x500':
159+
$namespace = Uuid::NAMESPACE_X500;
160+
break;
161+
default:
162+
try {
163+
$namespace = Uuid::fromString($namespace);
164+
} catch (\InvalidArgumentException $e) {
165+
$io->error(sprintf('Invalid namespace "%s": %s', $namespace, $e->getMessage()));
166+
167+
return 1;
168+
}
154169
}
155170
}
156171

‎src/Symfony/Component/Uid/Tests/Command/GenerateUlidCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Uid/Tests/Command/GenerateUlidCommandTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testFormat()
9090
Ulid::fromRfc4122(trim($commandTester->getDisplay()));
9191
}
9292

93-
public function testTimestampIncrementWhenGeneratingSeveralUlids()
93+
public function testUlidsAreDifferentWhenGeneratingSeveralNow()
9494
{
9595
$commandTester = new CommandTester(new GenerateUlidCommand());
9696

‎src/Symfony/Component/Uid/Tests/Command/GenerateUuidCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Uid/Tests/Command/GenerateUuidCommandTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,13 @@ public function testTimestampIncrementWhenGeneratingSeveralTimeBasedUuids()
220220

221221
$this->assertNotSame($uuids[0], $uuids[1]);
222222
}
223+
224+
public function testNamespacePredefinedKeyword()
225+
{
226+
$commandTester = new CommandTester(new GenerateUuidCommand());
227+
228+
$this->assertSame(0, $commandTester->execute(['--name-based' => 'https://symfony.com', '--namespace' => 'url']));
229+
230+
$this->assertSame('9c7d0eda-982d-5708-b4bd-79b3b179725d', (string) Uuid::fromRfc4122(trim($commandTester->getDisplay())));
231+
}
223232
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.