|
16 | 16 | use PHPDraft\Parse\JsonToHTML; |
17 | 17 |
|
18 | 18 | define('VERSION', '0'); |
19 | | -$values = UI::main($argv); |
20 | | - |
21 | | -$apib = new ApibFileParser($values['file']); |
22 | | -$apib = $apib->parse(); |
23 | | - |
24 | | -$json = new DrafterAPI($apib); |
25 | | -if (!(defined('DRAFTER_ONLINE_MODE') && DRAFTER_ONLINE_MODE === 1)) |
| 19 | +try |
26 | 20 | { |
27 | | - try |
28 | | - { |
29 | | - $json = new Drafter($apib); |
30 | | - } |
31 | | - catch (RuntimeException $exception) |
| 21 | + $values = UI::main($argv); |
| 22 | + $apib = new ApibFileParser($values['file']); |
| 23 | + $apib = $apib->parse(); |
| 24 | + |
| 25 | + $json = new DrafterAPI($apib); |
| 26 | + if (!(defined('DRAFTER_ONLINE_MODE') && DRAFTER_ONLINE_MODE === 1)) |
32 | 27 | { |
33 | | - file_put_contents('php://stderr', $exception->getMessage() . "\n"); |
34 | | - $options = [ |
35 | | - 'y' => 'Yes', |
36 | | - 'n' => 'No', |
37 | | - ]; |
38 | | - $answer = UI::ask('Do you want to use the online version? [y/n]', $options, 'y'); |
39 | | - if (!$answer) |
| 28 | + try |
40 | 29 | { |
41 | | - file_put_contents('php://stderr', 'Could not find a suitable drafter version'); |
42 | | - exit(1); |
| 30 | + $json = new Drafter($apib); |
| 31 | + } |
| 32 | + catch (\PHPDraft\Parse\ResourceException $exception) |
| 33 | + { |
| 34 | + file_put_contents('php://stderr', $exception->getMessage() . "\n"); |
| 35 | + $options = [ |
| 36 | + 'y' => 'Yes', |
| 37 | + 'n' => 'No', |
| 38 | + ]; |
| 39 | + $answer = UI::ask('Do you want to use the online version? [y/n]', $options, 'y'); |
| 40 | + if (!$answer) |
| 41 | + { |
| 42 | + throw new \RuntimeException('Could not find a suitable drafter version', 1); |
| 43 | + } |
43 | 44 | } |
44 | 45 | } |
45 | | -} |
46 | | - |
47 | | -$html = new JsonToHTML($json->parseToJson()); |
48 | | -$html->sorting = $values['sorting']; |
49 | | -$generator = $html->get_html($values['template'], $values['image'], $values['css'], $values['js']); |
50 | 46 |
|
| 47 | + $html = new JsonToHTML($json->parseToJson()); |
| 48 | + $html->sorting = $values['sorting']; |
| 49 | + $generator = $html->get_html($values['template'], $values['image'], $values['css'], $values['js']); |
| 50 | +} catch (RuntimeException $exception) |
| 51 | +{ |
| 52 | + file_put_contents('php://stderr', $exception->getMessage().PHP_EOL); |
| 53 | + exit($exception->getCode()); |
| 54 | +} |
51 | 55 |
|
52 | 56 | function phpdraft_var_dump(...$vars) |
53 | 57 | { |
|
0 commit comments