Repository navigation
Expand file tree
/
Copy pathphizz
More file actions
executable file
·142 lines (126 loc) · 5.22 KB
/
Copy pathphizz
File metadata and controls
executable file
·142 lines (126 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
use NunoMaduro\Collision\Provider as Collision;
use Phizz\Generator\Generators\PhizzGenerator;
use Phizz\Generator\Objects\Configuration;
use Phizz\Generator\Parsers\FileParser;
use Phizz\Generator\Parsers\SchemaParser;
use Phizz\Generator\Parsers\StaticParser;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
// create a new symfony console application
$application = new Application();
// register nunomaduro/collision
(new Collision)->register();
$application->add(new Command("generate"))
->addOption(
name: "schema",
mode: InputOption::VALUE_REQUIRED,
description: "RiotAPI schema file path/url",
default: "https://www.mingweisamuel.com/riotapi-schema/openapi-3.0.0.json"
)
->addOption(
name: "patch",
mode: InputOption::VALUE_REQUIRED,
description: "CommunityDragon version to inspect (latest, pbe, or a patch like 14.1)",
default: 'latest',
)
->addOption(
name: "routes",
mode: InputOption::VALUE_REQUIRED,
description: "RiotAPI routes table file path/url",
default: "https://www.mingweisamuel.com/riotapi-schema/routesTable.json"
)
->addOption(
name: "seasons",
mode: InputOption::VALUE_REQUIRED,
description: "RiotAPI seasons file path/url",
default: "https://www.mingweisamuel.com/riotapi-schema/enums/seasons.json"
)
->addOption(
name: "queues",
mode: InputOption::VALUE_REQUIRED,
description: "RiotAPI queues file path/url",
default: "https://www.mingweisamuel.com/riotapi-schema/enums/queues.json"
)
->addOption(
name: "maps",
mode: InputOption::VALUE_REQUIRED,
description: "RiotAPI maps file path/url",
default: "https://www.mingweisamuel.com/riotapi-schema/enums/maps.json"
)
->addOption(
name: "game-modes",
mode: InputOption::VALUE_REQUIRED,
description: "RiotAPI game modes file path/url",
default: "https://www.mingweisamuel.com/riotapi-schema/enums/gameModes.json"
)
->addOption(
name: "game-types",
mode: InputOption::VALUE_REQUIRED,
description: "RiotAPI game types file path/url",
default: "https://www.mingweisamuel.com/riotapi-schema/enums/gameTypes.json"
)
->addOption(
name: "queue-types",
mode: InputOption::VALUE_REQUIRED,
description: "RiotAPI queue types file path/url",
default: "https://www.mingweisamuel.com/riotapi-schema/enums/queueTypes.json"
)
->setCode(function (InputInterface $input, OutputInterface $output): int {
// function timer
$start = microtime(true);
// opening log
$output->writeln('');
$output->writeln(' <fg=cyan;options=bold>Phizz</> <fg=gray>· API Generator</>');
$output->writeln('');
// fetching the schema file
$output->writeln(' <bg=blue;fg=white;options=bold> FETCH </> Fetching schema file...');
$output->writeln('');
$sp = new SchemaParser(console: $output);
$schema = $sp->parse(entry: $input->getOption("schema"));
// fetching routes and constants
$output->writeln(' <bg=blue;fg=white;options=bold> FETCH </> Fetching routes and constants...');
$output->writeln('');
$fp = new FileParser(console: $output);
$routes = $fp->parse(entry: $input->getOption("routes"));
$season = $fp->parse(entry: $input->getOption("seasons"));
$queue = $fp->parse(entry: $input->getOption("queues"));
$map = $fp->parse(entry: $input->getOption("maps"));
$gameMode = $fp->parse(entry: $input->getOption("game-modes"));
$gameType = $fp->parse(entry: $input->getOption("game-types"));
$queueType = $fp->parse(entry: $input->getOption("queue-types"));
// fetching cdragon endpoints
$output->writeln(' <bg=blue;fg=white;options=bold> FETCH </> Fetching CommunityDragon endpoints...');
$output->writeln('');
$dp = new StaticParser(console: $output);
$endpoints = $dp->parse(entry: $input->getOption("patch"));
// generate the code
(new PhizzGenerator(config: new Configuration(
console: $output,
schema: $schema,
endpoints: $endpoints,
routes: $routes,
enums: [
'season' => $season,
'queue' => $queue,
'map' => $map,
'gameMode' => $gameMode,
'gameType' => $gameType,
'queueType' => $queueType,
],
)))->generate();
// log elapsed time
$elapsed = number_format(microtime(true) - $start, 2);
$output->writeln('');
$output->writeln(" <bg=green;fg=black;options=bold> DONE </> All files generated <fg=gray>·</> <fg=cyan>{$elapsed}s</>");
$output->writeln('');
// return success
return Command::SUCCESS;
});
/** @noinspection PhpUnhandledExceptionInspection */
$application->run();