-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
feaa40d
commit ac73b86
Showing
2 changed files
with
47 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Aloe\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class KeyGenerateCommand extends Command | ||
{ | ||
protected static $defaultName = 'key:generate'; | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setHelp('Run your frontend dev command') | ||
->setDescription('Run your frontend dev server'); | ||
} | ||
|
||
protected function generateKey() | ||
{ | ||
return 'base64:' . base64_encode(random_bytes(32)); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$directory = getcwd(); | ||
$env = file_get_contents("$directory/.env"); | ||
|
||
if (strpos($env, 'APP_KEY') !== false) { | ||
$output->writeln("<info>APP_KEY already exists. Regenerating APP_KEY</info>"); | ||
$env = preg_replace('/APP_KEY=(.*)/', "APP_KEY={$this->generateKey()}", $env); | ||
} else { | ||
$env = "APP_KEY={$this->generateKey()}\n$env"; | ||
} | ||
|
||
|
||
file_put_contents("$directory/.env", $env); | ||
|
||
$output->writeln("<info>APP_KEY generated successfully.</info>"); | ||
|
||
return 0; | ||
} | ||
} |
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