|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Shlinkio\Shlink\Installer\Config\Plugin; |
|
5
|
|
|
|
|
6
|
|
|
use Shlinkio\Shlink\Common\Util\StringUtilsTrait; |
|
7
|
|
|
use Shlinkio\Shlink\Installer\Model\CustomizableAppConfig; |
|
8
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
9
|
|
|
use function array_diff; |
|
10
|
|
|
use function array_keys; |
|
11
|
|
|
|
|
12
|
|
|
class ApplicationConfigCustomizer implements ConfigCustomizerInterface |
|
13
|
|
|
{ |
|
14
|
|
|
use StringUtilsTrait; |
|
15
|
|
|
|
|
16
|
|
|
private const SECRET = 'SECRET'; |
|
17
|
|
|
private const DISABLE_TRACK_PARAM = 'DISABLE_TRACK_PARAM'; |
|
18
|
|
|
private const EXPECTED_KEYS = [ |
|
19
|
|
|
self::SECRET, |
|
20
|
|
|
self::DISABLE_TRACK_PARAM, |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
3 |
|
public function process(SymfonyStyle $io, CustomizableAppConfig $appConfig): void |
|
24
|
|
|
{ |
|
25
|
3 |
|
$app = $appConfig->getApp(); |
|
26
|
3 |
|
$keysToAskFor = $appConfig->hasApp() ? array_diff(self::EXPECTED_KEYS, array_keys($app)) : self::EXPECTED_KEYS; |
|
27
|
|
|
|
|
28
|
3 |
|
if (empty($keysToAskFor)) { |
|
29
|
1 |
|
return; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
2 |
|
$io->title('APPLICATION'); |
|
33
|
2 |
|
foreach ($keysToAskFor as $key) { |
|
34
|
2 |
|
$app[$key] = $this->ask($io, $key); |
|
35
|
|
|
} |
|
36
|
2 |
|
$appConfig->setApp($app); |
|
37
|
2 |
|
} |
|
38
|
|
|
|
|
39
|
2 |
|
private function ask(SymfonyStyle $io, string $key) |
|
40
|
|
|
{ |
|
41
|
|
|
switch ($key) { |
|
42
|
2 |
|
case self::SECRET: |
|
43
|
1 |
|
return $io->ask( |
|
44
|
|
|
'Define a secret string that will be used to sign API tokens (leave empty to autogenerate one) ' |
|
45
|
1 |
|
. '<fg=red>[DEPRECATED. TO BE REMOVED]</>' |
|
46
|
1 |
|
) ?: $this->generateRandomString(32); |
|
47
|
2 |
|
case self::DISABLE_TRACK_PARAM: |
|
48
|
2 |
|
return $io->ask( |
|
49
|
|
|
'Provide a parameter name that you will be able to use to disable tracking on specific request to ' |
|
50
|
2 |
|
. 'short URLs (leave empty and this feature won\'t be enabled)' |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return ''; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|