Skip to content

Commit

Permalink
Add COMB and GUID options to command line
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibaud Fabre committed Feb 7, 2015
1 parent cc23f64 commit 8bece7c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Console/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.'
);
}

Expand All @@ -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'),
Expand Down
5 changes: 5 additions & 0 deletions src/UuidFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public function getCodec()
return $this->codec;
}

public function getRandomGenerator()
{
return $this->randomGenerator;
}

public function getNumberConverter()
{
return $this->numberConverter;
Expand Down

0 comments on commit 8bece7c

Please sign in to comment.