diff --git a/src/Console/Command/GenerateCommand.php b/src/Console/Command/GenerateCommand.php index 78a16692..09ff88d2 100644 --- a/src/Console/Command/GenerateCommand.php +++ b/src/Console/Command/GenerateCommand.php @@ -18,6 +18,10 @@ use Symfony\Component\Console\Output\OutputInterface; use Rhumsaa\Uuid\Console\Exception; use Rhumsaa\Uuid\Uuid; +use Rhumsaa\Uuid\Generator\CombGenerator; +use Rhumsaa\Uuid\Codec\GuidStringCodec; +use Rhumsaa\Uuid\FeatureSet; +use Rhumsaa\Uuid\UuidFactory; /** * Provides the console command to generate UUIDs @@ -60,6 +64,18 @@ protected function configure() InputOption::VALUE_REQUIRED, 'Generate count UUIDs instead of just a single one.', 1 + ) + ->addOption( + 'comb', + null, + InputOption::VALUE_NONE, + 'For version 4 UUIDs, uses the COMB strategy to generate the random data.' + ) + ->addOption( + 'guid', + 'g', + InputOption::VALUE_NONE, + 'Returns a GUID formatted UUID.' ); } @@ -82,6 +98,21 @@ protected function execute(InputInterface $input, OutputInterface $output) ) ); + if (((bool) $input->getOption('guid')) == true) { + $features = new FeatureSet(true); + + Uuid::setFactory(new UuidFactory($features)); + } + + if (((bool) $input->getOption('comb')) === true) { + Uuid::getFactory()->setRandomGenerator( + new CombGenerator( + Uuid::getFactory()->getRandomGenerator(), + Uuid::getFactory()->getNumberConverter() + ) + ); + } + for ($i = 0; $i < $count; $i++) { $uuids[] = $this->createUuid( $input->getArgument('version'), diff --git a/src/UuidFactory.php b/src/UuidFactory.php index 052feafb..632cb4d5 100644 --- a/src/UuidFactory.php +++ b/src/UuidFactory.php @@ -74,6 +74,11 @@ public function getCodec() return $this->codec; } + public function getRandomGenerator() + { + return $this->randomGenerator; + } + public function getNumberConverter() { return $this->numberConverter;