1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace BrowscapPHP\Command; |
5
|
|
|
|
6
|
|
|
use BrowscapPHP\BrowscapUpdater; |
7
|
|
|
use BrowscapPHP\Helper\IniLoader; |
8
|
|
|
use BrowscapPHP\Helper\LoggerHelper; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Command to fetch a browscap ini file from the remote host and store the content in a local file |
17
|
|
|
*/ |
18
|
|
|
class FetchCommand extends Command |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $defaultIniFile; |
24
|
|
|
|
25
|
1 |
|
public function __construct(string $defaultIniFile) |
26
|
|
|
{ |
27
|
1 |
|
$this->defaultIniFile = $defaultIniFile; |
28
|
|
|
|
29
|
1 |
|
parent::__construct(); |
30
|
1 |
|
} |
31
|
|
|
|
32
|
1 |
|
protected function configure() : void |
33
|
|
|
{ |
34
|
|
|
$this |
35
|
1 |
|
->setName('browscap:fetch') |
36
|
1 |
|
->setDescription('Fetches an updated INI file for Browscap.') |
37
|
1 |
|
->addArgument( |
38
|
1 |
|
'file', |
39
|
1 |
|
InputArgument::OPTIONAL, |
40
|
1 |
|
'browscap.ini file', |
41
|
1 |
|
$this->defaultIniFile |
42
|
|
|
) |
43
|
1 |
|
->addOption( |
44
|
1 |
|
'remote-file', |
45
|
1 |
|
'r', |
46
|
1 |
|
InputOption::VALUE_OPTIONAL, |
47
|
1 |
|
'browscap.ini file to download from remote location (possible values are: ' . IniLoader::PHP_INI_LITE |
48
|
1 |
|
. ', ' . IniLoader::PHP_INI . ', ' . IniLoader::PHP_INI_FULL . ')', |
49
|
1 |
|
IniLoader::PHP_INI |
50
|
|
|
) |
51
|
1 |
|
->addOption( |
52
|
1 |
|
'debug', |
53
|
1 |
|
'd', |
54
|
1 |
|
InputOption::VALUE_NONE, |
55
|
1 |
|
'Should the debug mode entered?' |
56
|
|
|
); |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) : void |
60
|
|
|
{ |
61
|
|
|
$loggerHelper = new LoggerHelper(); |
62
|
|
|
$logger = $loggerHelper->create($input->getOption('debug')); |
63
|
|
|
|
64
|
|
|
$file = $input->getArgument('file'); |
65
|
|
|
if (! $file) { |
66
|
|
|
$file = $this->defaultIniFile; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$logger->info('started fetching remote file'); |
70
|
|
|
|
71
|
|
|
$browscap = new BrowscapUpdater(); |
72
|
|
|
|
73
|
|
|
$browscap->setLogger($logger); |
74
|
|
|
$browscap->fetch($file, $input->getOption('remote-file')); |
75
|
|
|
|
76
|
|
|
$logger->info('finished fetching remote file'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|