@@ -9,6 +9,7 @@ set_include_path(get_include_path() . ":" . __DIR__ . '/src/');
9
9
*/
10
10
//require_once 'PHPDraft/Core/Autoloader.php';
11
11
require_once 'vendor/autoload.php';
12
+
12
13
use PHPDraft\In\ApibFileParser;
13
14
use PHPDraft\Out\UI;
14
15
use PHPDraft\Parse\Drafter;
@@ -18,41 +19,66 @@ use PHPDraft\Parse\JsonToHTML;
18
19
define('VERSION', '0');
19
20
try
20
21
{
21
- $values = UI::main($argv);
22
- $apib = new ApibFileParser($values['file']);
23
- $apib = $apib->parse();
22
+ $values = UI::main($argv);
23
+ $apib = new ApibFileParser($values['file']);
24
+ $apib = $apib->parse();
25
+ $offline = FALSE;
26
+ $online = FALSE;
24
27
25
- $json = new DrafterAPI($apib);
26
- if (!(defined('DRAFTER_ONLINE_MODE') && DRAFTER_ONLINE_MODE === 1))
28
+ try
29
+ {
30
+ $json = new Drafter($apib);
31
+ $offline = TRUE;
32
+ }
33
+ catch (\PHPDraft\Parse\ResourceException $exception)
34
+ {
35
+ file_put_contents('php://stderr', "Offline drafter not available.\n");
36
+ if (!defined('DRAFTER_ONLINE_MODE') || DRAFTER_ONLINE_MODE !== 1)
37
+ {
38
+ ask_version();
39
+ }
40
+ }
41
+ if (!$offline)
27
42
{
28
43
try
29
44
{
30
- $json = new Drafter($apib);
45
+ $json = new DrafterAPI($apib);
46
+ $online = TRUE;
31
47
}
32
48
catch (\PHPDraft\Parse\ResourceException $exception)
33
49
{
34
50
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
- }
44
51
}
45
52
}
53
+ if (!$online && !$offline)
54
+ {
55
+ throw new \RuntimeException('Could not find a suitable drafter version', 1);
56
+ }
57
+
46
58
47
59
$html = new JsonToHTML($json->parseToJson());
48
60
$html->sorting = $values['sorting'];
49
61
$generator = $html->get_html($values['template'], $values['image'], $values['css'], $values['js']);
50
- } catch (RuntimeException $exception)
62
+ }
63
+ catch (RuntimeException $exception)
51
64
{
52
- file_put_contents('php://stderr', $exception->getMessage(). PHP_EOL);
65
+ file_put_contents('php://stderr', $exception->getMessage() . PHP_EOL);
53
66
exit($exception->getCode());
54
67
}
55
68
69
+ function ask_version()
70
+ {
71
+ $options = [
72
+ 'y' => 'Yes',
73
+ 'n' => 'No',
74
+ ];
75
+ $answer = UI::ask('Do you want to use the online version? [y/n]', $options, 'y');
76
+ if (!$answer)
77
+ {
78
+ throw new \RuntimeException('Could not find a suitable drafter version', 1);
79
+ }
80
+ }
81
+
56
82
function phpdraft_var_dump(...$vars)
57
83
{
58
84
if (defined('__PHPDRAFT_PHAR__'))
0 commit comments