generate() public static method

Generates a set of numbers ready for use.
public static generate ( integer | null $prime = null ) : array
$prime integer | null
return array
Esempio n. 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         list($prime, $inverse, $rand) = Energon::generate($input->getArgument('prime'));
     } catch (InvalidPrimeException $e) {
         $output->writeln('<error>Invalid prime number</>');
         return;
     }
     $output->writeln('Prime: ' . $prime);
     $output->writeln('Inverse: ' . $inverse);
     $output->writeln('Random: ' . $rand);
     $output->writeln('');
     $output->writeln('    new Optimus(' . $prime . ', ' . $inverse . ', ' . $rand . ');');
 }
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     list($prime, $inverse, $rand) = Energon::generate();
     // Write in environment file.
     $path = base_path('.env');
     if (!file_exists($path)) {
         $this->error("Environment file (.env) not found. Aborting FakeId setup!");
         return;
     }
     // Remove existing configuration.
     $fileArray = file($path);
     foreach ($fileArray as $k => $line) {
         if (strpos($line, 'FAKEID_') === 0) {
             unset($fileArray[$k]);
         }
     }
     // Append new configuration.
     $fileArray[] = "\nFAKEID_PRIME=" . $prime;
     $fileArray[] = "\nFAKEID_INVERSE=" . $inverse;
     $fileArray[] = "\nFAKEID_RANDOM=" . $rand;
     file_put_contents($path, implode('', $fileArray), LOCK_EX);
     $this->info("FakeId configured correctly.");
 }