|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PHPTdGram\SchemaGenerator\Console; |
|
6
|
|
|
|
|
7
|
|
|
use PHPTdGram\SchemaGenerator\CodeGenerator; |
|
8
|
|
|
use PHPTdGram\SchemaGenerator\SchemaParser; |
|
9
|
|
|
use Symfony\Component\Console\Application as SfApplication; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author Aurimas Niekis <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class Application extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
private string $version = '1.0'; |
|
21
|
|
|
private bool $running = false; |
|
22
|
|
|
|
|
23
|
|
|
public function run(InputInterface $input = null, OutputInterface $output = null): int |
|
24
|
|
|
{ |
|
25
|
|
|
if ($this->running) { |
|
26
|
|
|
return parent::run($input, $output); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$application = new SfApplication($this->getName() ?: 'UNKNOWN', $this->version); |
|
30
|
|
|
|
|
31
|
|
|
$this->setName($_SERVER['argv'][0]); |
|
32
|
|
|
$application->add($this); |
|
33
|
|
|
$application->setDefaultCommand($this->getName(), true); |
|
34
|
|
|
|
|
35
|
|
|
$this->running = true; |
|
36
|
|
|
|
|
37
|
|
|
try { |
|
38
|
|
|
$ret = $application->run($input, $output); |
|
39
|
|
|
} finally { |
|
40
|
|
|
$this->running = false; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return $ret ?? 1; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function configure(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->addArgument( |
|
49
|
|
|
'tl_file', |
|
50
|
|
|
InputArgument::OPTIONAL, |
|
51
|
|
|
'Telegram TL file to generate classes from' |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
56
|
|
|
{ |
|
57
|
|
|
$parser = new SchemaParser($output, $input->getArgument('tl_file')); |
|
|
|
|
|
|
58
|
|
|
$classes = $parser->parse(); |
|
59
|
|
|
|
|
60
|
|
|
$generator = new CodeGenerator('PHPTdGram\Schema', __DIR__ . '/../../schema/src'); |
|
61
|
|
|
$generator->generate($classes); |
|
62
|
|
|
|
|
63
|
|
|
return 0; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|