|
1
|
|
|
<?php |
|
2
|
|
|
namespace Shlinkio\Shlink\CLI\Install\Plugin; |
|
3
|
|
|
|
|
4
|
|
|
use Shlinkio\Shlink\CLI\Model\CustomizableAppConfig; |
|
5
|
|
|
use Shlinkio\Shlink\Core\Service\UrlShortener; |
|
6
|
|
|
use Symfony\Component\Console\Exception\RuntimeException; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
|
10
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
|
11
|
|
|
|
|
12
|
|
|
class UrlShortenerConfigCustomizerPlugin extends AbstractConfigCustomizerPlugin |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param InputInterface $input |
|
16
|
|
|
* @param OutputInterface $output |
|
17
|
|
|
* @param CustomizableAppConfig $appConfig |
|
18
|
|
|
* @return void |
|
19
|
|
|
* @throws RuntimeException |
|
20
|
|
|
*/ |
|
21
|
3 |
|
public function process(InputInterface $input, OutputInterface $output, CustomizableAppConfig $appConfig) |
|
22
|
|
|
{ |
|
23
|
3 |
|
$this->printTitle($output, 'URL SHORTENER'); |
|
24
|
|
|
|
|
25
|
3 |
|
if ($appConfig->hasUrlShortener() && $this->questionHelper->ask($input, $output, new ConfirmationQuestion( |
|
26
|
3 |
|
'<question>Do you want to keep imported URL shortener config? (Y/n):</question> ' |
|
27
|
|
|
))) { |
|
28
|
1 |
|
return; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
// Ask for URL shortener params |
|
32
|
2 |
|
$appConfig->setUrlShortener([ |
|
33
|
2 |
|
'SCHEMA' => $this->questionHelper->ask($input, $output, new ChoiceQuestion( |
|
34
|
2 |
|
'<question>Select schema for generated short URLs (defaults to http):</question>', |
|
35
|
2 |
|
['http', 'https'], |
|
36
|
|
|
0 |
|
37
|
|
|
)), |
|
38
|
2 |
|
'HOSTNAME' => $this->ask($input, $output, 'Hostname for generated URLs'), |
|
39
|
2 |
|
'CHARS' => $this->ask( |
|
40
|
2 |
|
$input, |
|
41
|
2 |
|
$output, |
|
42
|
2 |
|
'Character set for generated short codes (leave empty to autogenerate one)', |
|
43
|
2 |
|
null, |
|
44
|
2 |
|
true |
|
45
|
2 |
|
) ?: str_shuffle(UrlShortener::DEFAULT_CHARS) |
|
46
|
|
|
]); |
|
47
|
2 |
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|