1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stp\SndApi\News\Command; |
4
|
|
|
|
5
|
|
|
use SoapBox\Formatter\Formatter; |
6
|
|
|
use Stp\SndApi\Common\Command\BaseCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class ArticlesBySectionIdCommand extends BaseCommand |
12
|
|
|
{ |
13
|
|
|
use NewsClientCommandTrait; |
14
|
|
|
|
15
|
|
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
parent::configure(); |
18
|
|
|
|
19
|
|
|
$this |
20
|
|
|
->setName('news:section:articles') |
21
|
|
|
->addArgument( |
22
|
|
|
'id', |
23
|
|
|
InputArgument::REQUIRED, |
24
|
|
|
'Section ID' |
25
|
|
|
) |
26
|
|
|
->addArgument( |
27
|
|
|
'method', |
28
|
|
|
InputArgument::REQUIRED, |
29
|
|
|
'Articles list method (desked, auto)' |
30
|
|
|
) |
31
|
|
|
->addArgument( |
32
|
|
|
'parameters', |
33
|
|
|
InputArgument::IS_ARRAY | InputArgument::OPTIONAL, |
34
|
|
|
'List of parameters i.e. limit=50' |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param InputInterface $input |
40
|
|
|
* @param OutputInterface $output |
41
|
|
|
* @return int |
42
|
|
|
* @throws \Stp\SndApi\News\Exception\InvalidMethodException |
43
|
|
|
* @throws \Stp\SndApi\News\Exception\InvalidMethodParametersException |
44
|
|
|
*/ |
45
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
46
|
|
|
{ |
47
|
|
|
$newsClient = $this->getNewsClient($input); |
48
|
|
|
|
49
|
|
|
$sectionId = $input->getArgument('id'); |
50
|
|
|
$method = $input->getArgument('method'); |
51
|
|
|
$parameterStrings = $input->getArgument('parameters'); |
52
|
|
|
$parameters = []; |
53
|
|
|
|
54
|
|
|
foreach ($parameterStrings as $parameter) { |
55
|
|
|
$parameterData = explode('=', $parameter); |
56
|
|
|
|
57
|
|
|
$parameters[$parameterData[0]] = $parameterData[1]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$result = $newsClient->getArticlesBySectionId($sectionId, $method, $parameters); |
61
|
|
|
$formatter = Formatter::make($result, Formatter::ARR); |
62
|
|
|
|
63
|
|
|
$output->writeln($formatter->toYaml()); |
64
|
|
|
|
65
|
|
|
return 0; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|