1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Efabrica\TranslationsAutomatization\TranslationMaker\Command; |
4
|
|
|
|
5
|
|
|
use Efabrica\TranslationsAutomatization\Exception\InvalidConfigInstanceReturnedException; |
6
|
|
|
use Efabrica\TranslationsAutomatization\TranslationMaker\TranslationMaker; |
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
|
13
|
|
|
class TranslationMakerCommand extends Command |
14
|
|
|
{ |
15
|
|
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
$this->setName('maker') |
18
|
|
|
->setDescription('Creates new language version of translated texts') |
19
|
|
|
->addOption('config', null, InputOption::VALUE_REQUIRED, 'Path to config file. Instance of TranslationMaker have to be returned') |
20
|
|
|
->addOption('params', null, InputOption::VALUE_REQUIRED, 'Params for config in format a=b&c=d'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
24
|
|
|
{ |
25
|
|
|
if (!is_file($input->getOption('config'))) { |
26
|
|
|
throw new InvalidArgumentException('File "' . $input->getOption('config') . '" does not exist'); |
27
|
|
|
} |
28
|
|
|
parse_str($input->getOption('params'), $params); |
29
|
|
|
extract($params); |
30
|
|
|
|
31
|
|
|
$translationMaker = require_once $input->getOption('config'); |
32
|
|
|
if (!$translationMaker instanceof TranslationMaker) { |
33
|
|
|
throw new InvalidConfigInstanceReturnedException('"' . (is_object($translationMaker) ? get_class($translationMaker) : $translationMaker) . '" is not instance of ' . TranslationMaker::class); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$translationMaker->make(); |
37
|
|
|
$output->writeln('<comment>DONE</comment>'); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|