|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Spiral Framework. |
|
4
|
|
|
* |
|
5
|
|
|
* @license MIT |
|
6
|
|
|
* @author Anton Titov (Wolfy-J) |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Spiral\Commands\Spiral; |
|
9
|
|
|
|
|
10
|
|
|
use Spiral\Console\Command; |
|
11
|
|
|
use Spiral\Core\DirectoriesInterface; |
|
12
|
|
|
use Spiral\Encrypter\Configs\EncrypterConfig; |
|
13
|
|
|
use Spiral\Encrypter\EncrypterManager; |
|
14
|
|
|
use Spiral\Files\FilesInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Updates encryption key in root/.env file. Same logic as in Laravel. |
|
18
|
|
|
*/ |
|
19
|
|
|
class KeyCommand extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $name = 'app:key'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $description = 'Update application encryption key'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param DirectoriesInterface $directories |
|
33
|
|
|
* @param FilesInterface $files |
|
34
|
|
|
* @param EncrypterConfig $config |
|
35
|
|
|
* @param EncrypterManager $encrypterManager |
|
36
|
|
|
*/ |
|
37
|
|
|
public function perform( |
|
38
|
|
|
DirectoriesInterface $directories, |
|
39
|
|
|
FilesInterface $files, |
|
40
|
|
|
EncrypterConfig $config, |
|
41
|
|
|
EncrypterManager $encrypterManager |
|
42
|
|
|
) { |
|
43
|
|
|
$envFilename = $directories->directory('root') . '.env'; |
|
44
|
|
|
|
|
45
|
|
|
if (!$files->exists($envFilename)) { |
|
46
|
|
|
$this->writeln( |
|
47
|
|
|
"<fg=red>'env.' file does not exists, unable to sek encryption key.</fg=red>" |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$environmentData = $files->read($envFilename); |
|
52
|
|
|
|
|
53
|
|
|
$environmentData = str_replace( |
|
54
|
|
|
base64_encode($config->getKey()), |
|
55
|
|
|
base64_encode($encrypterManager->generateKey()), |
|
|
|
|
|
|
56
|
|
|
$environmentData |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
$files->write($envFilename, $environmentData); |
|
60
|
|
|
|
|
61
|
|
|
$this->writeln("<info>Encryption key has been successfully updated.</info>"); |
|
62
|
|
|
} |
|
63
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.