From b53bfaec5376843f3bf89f99e70ae033a096027f Mon Sep 17 00:00:00 2001 From: Clemens Krack Date: Thu, 20 Sep 2018 10:48:36 +0200 Subject: [PATCH 1/3] Add format option to spark command Using this option allows to specify a format for the generated values. Using this, we can directly pipe the output into a file. --- src/Commands/SparkCommand.php | 46 +++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/src/Commands/SparkCommand.php b/src/Commands/SparkCommand.php index 4ba2635..e6d05ad 100644 --- a/src/Commands/SparkCommand.php +++ b/src/Commands/SparkCommand.php @@ -24,6 +24,12 @@ protected function configure() InputOption::VALUE_REQUIRED, 'The number of bits used to obfuscate the integer. E.g. 16 bits will produce numbers in the range 0 to 65535.', Optimus::DEFAULT_SIZE + )->addOption( + 'format', + 'f', + InputOption::VALUE_OPTIONAL, + 'The output format. Tip: Use --format=env to directly generate env variables.', + 'txt' )->addArgument( 'prime', InputArgument::OPTIONAL, @@ -57,21 +63,31 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Invalid prime number'); return 1; - } + } - $output->writeln('Prime: ' . $prime); - $output->writeln('Inverse: ' . $inverse); - $output->writeln('Random: ' . $rand); - $output->writeln('Bit length: ' . $bitLength); - $output->writeln(''); - $output->writeln( - sprintf( - ' new Optimus(%s, %s, %s, %s);', - $prime, - $inverse, - $rand, - $bitLength - ) - ); + switch ($input->getOption('format')) { + case 'env': + $output->writeln('OPTIMUS_PRIME=' . $prime); + $output->writeln('OPTIMUS_INVERSE=' . $inverse); + $output->writeln('OPTIMUS_RANDOM=' . $rand); + $output->writeln('OPTIMUS_BITLENGTH=' . $bitLength); + break; + default: + $output->writeln('Prime: ' . $prime); + $output->writeln('Inverse: ' . $inverse); + $output->writeln('Random: ' . $rand); + $output->writeln('Bit length: ' . $bitLength); + $output->writeln(''); + $output->writeln( + sprintf( + ' new Optimus(%s, %s, %s, %s);', + $prime, + $inverse, + $rand, + $bitLength + ) + ); + break; + } } } From ff6ae0cf759934dc9fd63337e8cd92f17d4335c0 Mon Sep 17 00:00:00 2001 From: Clemens Krack Date: Thu, 20 Sep 2018 10:49:04 +0200 Subject: [PATCH 2/3] Add htaccess SetEnv format --- src/Commands/SparkCommand.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Commands/SparkCommand.php b/src/Commands/SparkCommand.php index e6d05ad..801ef07 100644 --- a/src/Commands/SparkCommand.php +++ b/src/Commands/SparkCommand.php @@ -72,6 +72,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('OPTIMUS_RANDOM=' . $rand); $output->writeln('OPTIMUS_BITLENGTH=' . $bitLength); break; + case 'htaccess': + $output->writeln('SetEnv OPTIMUS_PRIME ' . $prime); + $output->writeln('SetEnv OPTIMUS_INVERSE ' . $inverse); + $output->writeln('SetEnv OPTIMUS_RANDOM ' . $rand); + $output->writeln('SetEnv OPTIMUS_BITLENGTH ' . $bitLength); + break; default: $output->writeln('Prime: ' . $prime); $output->writeln('Inverse: ' . $inverse); From 4e76f80ee93fc860c0ed04b2868609dee907fb80 Mon Sep 17 00:00:00 2001 From: Clemens Krack Date: Thu, 20 Sep 2018 11:04:59 +0200 Subject: [PATCH 3/3] Fix indents --- src/Commands/SparkCommand.php | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Commands/SparkCommand.php b/src/Commands/SparkCommand.php index 801ef07..aee3896 100644 --- a/src/Commands/SparkCommand.php +++ b/src/Commands/SparkCommand.php @@ -63,37 +63,37 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Invalid prime number'); return 1; - } + } - switch ($input->getOption('format')) { - case 'env': - $output->writeln('OPTIMUS_PRIME=' . $prime); - $output->writeln('OPTIMUS_INVERSE=' . $inverse); - $output->writeln('OPTIMUS_RANDOM=' . $rand); - $output->writeln('OPTIMUS_BITLENGTH=' . $bitLength); - break; - case 'htaccess': - $output->writeln('SetEnv OPTIMUS_PRIME ' . $prime); - $output->writeln('SetEnv OPTIMUS_INVERSE ' . $inverse); - $output->writeln('SetEnv OPTIMUS_RANDOM ' . $rand); - $output->writeln('SetEnv OPTIMUS_BITLENGTH ' . $bitLength); - break; - default: - $output->writeln('Prime: ' . $prime); - $output->writeln('Inverse: ' . $inverse); - $output->writeln('Random: ' . $rand); - $output->writeln('Bit length: ' . $bitLength); - $output->writeln(''); - $output->writeln( - sprintf( - ' new Optimus(%s, %s, %s, %s);', - $prime, - $inverse, - $rand, - $bitLength - ) - ); - break; - } + switch ($input->getOption('format')) { + case 'env': + $output->writeln('OPTIMUS_PRIME=' . $prime); + $output->writeln('OPTIMUS_INVERSE=' . $inverse); + $output->writeln('OPTIMUS_RANDOM=' . $rand); + $output->writeln('OPTIMUS_BITLENGTH=' . $bitLength); + break; + case 'htaccess': + $output->writeln('SetEnv OPTIMUS_PRIME ' . $prime); + $output->writeln('SetEnv OPTIMUS_INVERSE ' . $inverse); + $output->writeln('SetEnv OPTIMUS_RANDOM ' . $rand); + $output->writeln('SetEnv OPTIMUS_BITLENGTH ' . $bitLength); + break; + default: + $output->writeln('Prime: ' . $prime); + $output->writeln('Inverse: ' . $inverse); + $output->writeln('Random: ' . $rand); + $output->writeln('Bit length: ' . $bitLength); + $output->writeln(''); + $output->writeln( + sprintf( + ' new Optimus(%s, %s, %s, %s);', + $prime, + $inverse, + $rand, + $bitLength + ) + ); + break; + } } }