/** * @param Event $event */ public static function addSalts(Event $event) { static::$root = dirname(dirname(__DIR__)); static::$envFilePath = static::$root . '/.env'; static::$io = $event->getIO(); $generate_salts = false; // Only add new/regenerate salts if we are doing a fresh install and specify "yes" to the question. // This way the salts aren't cleared whenever a `composer install` is done on deploy. if (static::$io->isInteractive()) { $generate_salts = static::$io->askConfirmation('<info>Generate salts and append to .env file?</info> [<comment>Y,n</comment>]? ', true); } // No need to continue - exit. if (!$generate_salts) { return; } // Open the file for writing. $handle = fopen(static::$envFilePath, 'a'); $keys = []; // Get the salt keys. foreach (static::$saltKeys as $key) { $keys[] = static::getEnvVar($key, Installer::generateSalt()); } // Append additional keys to the .env file/keys array. foreach (static::setEnvironmentVariables() as $key => $val) { $keys[] = static::getEnvVar($key, $val); } if ($handle) { fwrite($handle, implode($keys, "\n")); fclose($handle); } }