Skip to content

Instantly share code, notes, and snippets.

@crossmaya
Last active December 29, 2019 10:40
Show Gist options
  • Save crossmaya/2860ebe152359a5b07df2272b57b917c to your computer and use it in GitHub Desktop.
Save crossmaya/2860ebe152359a5b07df2272b57b917c to your computer and use it in GitHub Desktop.
php代码片段
//动态修改env文件
$path = base_path('.env');
if (file_exists($path)) {
//Try to read the current content of .env
$current = file_get_contents($path);
//Store the key
$original = [];
if (preg_match('/^XCHACHA_KEY=(.+)$/m', $current, $original)) {
//Write the original key to console
$this->info("Original XChaCha key: $original[0]");
//Overwrite with new key
$current = preg_replace('/^XCHACHA_KEY=.+$/m', "XCHACHA_KEY=$b64", $current);
} else {
//Append the key to the end of file
$current .= PHP_EOL."XCHACHA_KEY=$b64";
}
file_put_contents($path, $current);
}
$this->info('Successfully generated new key for XChaCha');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment