-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate APP_SECRET in .env.local when missing
- Loading branch information
1 parent
22d4acf
commit bef9131
Showing
3 changed files
with
18 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
$env = file_get_contents('.env'); | ||
|
||
if (!preg_match('{^APP_SECRET=("?)%generate\(secret\)%\1([\r\n]++)}m', $env, $m)) { | ||
return; | ||
} | ||
|
||
$eol = $m[2]; | ||
$local = is_file('.env.local') ? file_get_contents('.env.local') : ''; | ||
|
||
if (preg_match('{^APP_SECRET=}m', $local)) { | ||
return; | ||
} | ||
|
||
file_put_contents('.env.local', 'APP_SECRET="'.bin2hex(random_bytes(16)).'"'.$eol.$local); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters