|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SixtyNine\Cloud\Command; |
|
4
|
|
|
|
|
5
|
|
|
use SixtyNine\Cloud\Builder\FiltersBuilder; |
|
6
|
|
|
use SixtyNine\Cloud\Builder\WordsListBuilder; |
|
7
|
|
|
use SixtyNine\Cloud\Serializer; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
class ImportUrlCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
protected function configure() |
|
17
|
|
|
{ |
|
18
|
|
|
$this |
|
19
|
|
|
->setName('import-url') |
|
20
|
|
|
->setDescription('Create a words list from a URL') |
|
21
|
|
|
->addArgument('url', InputArgument::REQUIRED, 'The URL for the words') |
|
22
|
|
|
->addOption('case', null, InputOption::VALUE_OPTIONAL, 'Change case filter type (uppercase, lowercase, ucfirst)') |
|
23
|
|
|
->addOption('max-count', null, InputOption::VALUE_OPTIONAL, 'Maximum number of words', 100) |
|
24
|
|
|
->addOption('min-length', null, InputOption::VALUE_OPTIONAL, 'Minimumal word length', 5) |
|
25
|
|
|
->addOption('max-length', null, InputOption::VALUE_OPTIONAL, 'Maximal word length', 10) |
|
26
|
|
|
->addOption('no-remove-numbers', null, InputOption::VALUE_NONE, 'Disable the remove numbers filter') |
|
27
|
|
|
->addOption('no-remove-trailing', null, InputOption::VALUE_NONE, 'Disable the remove trailing characters filter') |
|
28
|
|
|
->addOption('no-remove-unwanted', null, InputOption::VALUE_NONE, 'Disable the remove unwanted characters filter') |
|
29
|
|
|
; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
33
|
|
|
{ |
|
34
|
|
|
$filtersBuilder = FiltersBuilder::create() |
|
35
|
|
|
->setMinLength($input->getOption('min-length')) |
|
36
|
|
|
->setMaxLength($input->getOption('max-length')) |
|
37
|
|
|
->setRemoveNumbers(!$input->getOption('no-remove-numbers')) |
|
38
|
|
|
->setRemoveUnwanted(!$input->getOption('no-remove-unwanted')) |
|
39
|
|
|
->setRemoveTrailing(!$input->getOption('no-remove-trailing')) |
|
40
|
|
|
; |
|
41
|
|
|
|
|
42
|
|
|
$case = $input->getOption('case'); |
|
43
|
|
|
|
|
44
|
|
|
if ($case && in_array($case, $filtersBuilder->getAllowedCase())) { |
|
45
|
|
|
$filtersBuilder->setCase($case); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$list = WordsListBuilder::create() |
|
49
|
|
|
->setMaxWords($input->getOption('max-count')) |
|
50
|
|
|
->setFilters($filtersBuilder->build()) |
|
51
|
|
|
->importUrl($input->getArgument('url')) |
|
52
|
|
|
->build('list') |
|
53
|
|
|
; |
|
54
|
|
|
|
|
55
|
|
|
$serializer = new Serializer(); |
|
56
|
|
|
$json = $serializer->saveList($list, true); |
|
57
|
|
|
echo $json . PHP_EOL; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|