/** * Ask user for interaction. * * @return void */ public function askForInteraction() { $str = Console::ansiFormat('Do you want to interact with this script?', [$this->colorNotable]); $this->interactive = $this->confirm($str, true); }
/** * Set cookie validation key in .env file. * * @param array $paths the file paths (keys) and the corresponding patterns to search for (values). * @throws Exception */ public static function setCookieValidationKey(array $paths = ['.env' => '<cookie_validation_key>']) { if (!extension_loaded('openssl')) { throw new Exception('The OpenSSL PHP extension is required.'); } foreach ($paths as $file => $pattern) { if (is_file($file)) { Console::stdout("Generating cookie validation key in {$file}", Console::FG_GREY); $content = file_get_contents($file); $content = preg_replace_callback("/{$pattern}/m", function () { $length = 32; $bytes = openssl_random_pseudo_bytes(32, $crypto_strong); return strtr(substr(base64_encode($bytes), 0, $length), '+/', '_-'); }, $content); file_put_contents($file, $content); } else { Console::stderr("{$file} not found", Console::FG_RED); } } }