1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Saxulum\ElasticSearchQueryBuilder\Generator\Command; |
6
|
|
|
|
7
|
|
|
use PhpParser\PrettyPrinter\Standard as PhpGenerator; |
8
|
|
|
use Saxulum\ElasticSearchQueryBuilder\Generator\QueryBuilderGenerator; |
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
|
|
|
* @deprecated use Saxulum\ElasticSearchQueryBuilder\Generator\Command\NodeGeneratorCommand |
17
|
|
|
*/ |
18
|
|
|
final class QueryBuilderGeneratorCommand extends Command |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param string|null $name |
22
|
|
|
*/ |
23
|
2 |
|
public function __construct($name = null) |
24
|
|
|
{ |
25
|
2 |
|
parent::__construct($name); |
26
|
|
|
|
27
|
2 |
|
@trigger_error(sprintf('Use "%s" instead of the "%s"', NodeGeneratorCommand::class, self::class), E_USER_DEPRECATED); |
|
|
|
|
28
|
2 |
|
} |
29
|
|
|
|
30
|
2 |
|
protected function configure() |
31
|
|
|
{ |
32
|
|
|
$this |
33
|
2 |
|
->setName('saxulum:elasticsearch:querybuilder:generator:querybuilder') |
34
|
2 |
|
->setDescription('Generate the node code of a elasticsearch json query.') |
35
|
2 |
|
->addArgument('query', InputArgument::REQUIRED, 'The json query.') |
36
|
2 |
|
->addOption('useMethodName', 'm', InputOption::VALUE_NONE, 'Use method names as addToObjectNode') |
37
|
|
|
; |
38
|
2 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param InputInterface $input |
42
|
|
|
* @param OutputInterface $output |
43
|
|
|
* |
44
|
|
|
* @return int |
45
|
|
|
*/ |
46
|
2 |
View Code Duplication |
protected function execute(InputInterface $input, OutputInterface $output) |
|
|
|
|
47
|
|
|
{ |
48
|
2 |
|
$generator = new QueryBuilderGenerator(new PhpGenerator(), $input->getOption('useMethodName')); |
|
|
|
|
49
|
|
|
|
50
|
2 |
|
$output->writeln('<info>Generated code:</info>'); |
51
|
2 |
|
$output->writeln($generator->generateByJson($input->getArgument('query'))); |
52
|
|
|
|
53
|
2 |
|
return 0; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: