Skip to content

Commit 00b7dbb

Browse files
Sean MolenaarSean Molenaar
authored andcommitted
Checking drafter install before run
1 parent 98a2a68 commit 00b7dbb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/PHPDraft/Parse/ApibToJson.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,28 @@ public function parseToJson()
5454
}
5555

5656
file_put_contents($tmp_dir . '/index.apib', $this->apib);
57+
if (!$this->drafter_location()) {
58+
$fe = fopen('php://stderr', 'w');
59+
fwrite($fe, "Drafter was not installed!\n");
60+
exit(1);
61+
}
5762

58-
system('/usr/local/bin/drafter ' . $tmp_dir . '/index.apib -f json > ' . $tmp_dir . '/index.json 2> /dev/null');
63+
shell_exec($this->drafter_location(). ' ' . $tmp_dir . '/index.apib -f json -o ' . $tmp_dir . '/index.json 2> /dev/null');
5964
$this->json = file_get_contents($tmp_dir . '/index.json');
6065
return $this->apib;
6166
}
6267

68+
/**
69+
* Return drafter location if found
70+
*
71+
* @return bool|string
72+
*/
73+
function drafter_location() {
74+
$returnVal = shell_exec('which drafter 2> /dev/null');
75+
$returnVal = preg_replace('/^\s+|\n|\r|\s+$/m', '', $returnVal);
76+
return (empty($returnVal) ? FALSE : $returnVal);
77+
}
78+
6379
/**
6480
* JSON representation
6581
*

0 commit comments

Comments
 (0)