Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions phpdraft
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,18 @@ try
Version::version();
throw new ExecutionException('', 0);
}
if (!(isset($args['file']) || isset($args['debug-json-file']) || isset($args['debug-json']))) {

stream_set_blocking(STDIN, false);
$stdin = stream_get_contents(STDIN);
$file = $args->getOpt('file');
if (!empty($stdin) && $file !== NULL) {
throw new ExecutionException('ERROR: Passed data in both file and stdin', 2);
} elseif (!empty($stdin) && $file === NULL) {
$file = tempnam(sys_get_temp_dir(), 'phpdraft');
file_put_contents($file, $stdin);
}

if (!($file !== NULL || isset($args['debug-json-file']) || isset($args['debug-json']))) {
throw new ExecutionException('Missing required option: file', 1);
}

Expand All @@ -53,10 +64,10 @@ try
}

if (!isset($args['debug-json-file']) && !isset($args['debug-json'])) {
$apib = new ApibFileParser($args->getOpt('file'));
$apib = $apib->parse();
$offline = FALSE;
$online = FALSE;
$apib_parser = new ApibFileParser($file);
$apib = $apib_parser->parse();
$offline = FALSE;
$online = FALSE;

try {
$parser = ParserFactory::getDrafter();
Expand Down