| Conditions | 3 |
| Paths | 3 |
| Total Lines | 16 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 13 | public function actionKey(bool $dryRun = false, string $filename = '.env') |
||
| 14 | { |
||
| 15 | $environmentFilePath = Yii::getAlias('@app/' . $filename); |
||
| 16 | Loader::load('', $filename, true); |
||
| 17 | foreach (['COOKIE_VALIDATION_KEY', 'JWT_SECRET'] as $item) { |
||
| 18 | $escaped = preg_quote('=' . env($item), '/'); |
||
|
|
|||
| 19 | $keyReplacementPattern = "/^{$item}{$escaped}/m"; |
||
| 20 | $key = Security::generateRealUniqId(32); |
||
| 21 | if (!$dryRun) { |
||
| 22 | file_put_contents($environmentFilePath, preg_replace( |
||
| 23 | $keyReplacementPattern, |
||
| 24 | "{$item}={$key}", |
||
| 25 | file_get_contents($environmentFilePath) |
||
| 26 | )); |
||
| 27 | } |
||
| 28 | $this->stdout("{$item} key [{$key}] set successfully.\n", Console::FG_GREEN); |
||
| 29 | } |
||
| 32 |