1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace xiaodi\JWTAuth\Command; |
||
6 | |||
7 | use Nette\PhpGenerator\Helpers; |
||
8 | use Nette\PhpGenerator\PhpFile; |
||
9 | use think\console\Command; |
||
10 | use think\console\Input; |
||
11 | use think\console\Output; |
||
12 | |||
13 | function randomKey() |
||
14 | { |
||
15 | $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~0123456789#$%^&'; |
||
16 | $pass = []; |
||
17 | $alphaLength = strlen($alphabet) - 1; |
||
18 | for ($i = 0; $i < 10; $i++) { |
||
19 | $n = rand(0, $alphaLength); |
||
20 | $pass[] = $alphabet[$n]; |
||
21 | } |
||
22 | |||
23 | return implode($pass); |
||
24 | } |
||
25 | |||
26 | class JwtCommand extends Command |
||
27 | { |
||
28 | protected function configure() |
||
29 | { |
||
30 | $this->setName('jwt:make')->setDescription('生成一个签名密钥'); |
||
31 | } |
||
32 | |||
33 | protected function execute(Input $input, Output $output) |
||
34 | { |
||
35 | $file = new PhpFile(); |
||
36 | $file->addComment('Jwt 配置'); |
||
37 | $file->setStrictTypes(); |
||
38 | |||
39 | $config = config('jwt'); |
||
40 | $config['default']['signerKey'] = randomKey(); |
||
41 | $config = 'return '.Helpers::dump($config).';'; |
||
0 ignored issues
–
show
|
|||
42 | |||
43 | file_put_contents($this->app->getConfigPath().'jwt.php', $file.$config); |
||
44 | $output->writeln('> success!'); |
||
45 | } |
||
46 | } |
||
47 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.