-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathGenerateKeyCommand.php
More file actions
38 lines (28 loc) · 956 Bytes
/
GenerateKeyCommand.php
File metadata and controls
38 lines (28 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace Bow\Console\Command;
use Bow\Console\AbstractCommand;
use Bow\Console\Color;
use Bow\Console\Exception\ConsoleException;
class GenerateKeyCommand extends AbstractCommand
{
/**
* Generate Key
*
* @return void
* @throws ConsoleException
*/
public function generate(): void
{
$key = base64_encode(openssl_random_pseudo_bytes(12) . date('Y-m-d H:i:s') . microtime(true));
$env_file = config('app.env_file');
if (!file_exists($env_file)) {
throw new ConsoleException("The .env.json file not found. Run cp .env.example.json .env.json");
}
$contents = file_get_contents($env_file);
$contents = preg_replace('@"APP_KEY"\s*:\s*".*?"@', '"APP_KEY": "' . $key . '"', $contents);
file_put_contents($env_file, $contents);
echo sprintf("Application key => %s\n", Color::green($key));
exit;
}
}