From e819133c35acaee0d45592818d6f950b7e53bffd Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Tue, 18 Dec 2018 15:44:54 -0800 Subject: [PATCH] Use server_{input,output} for request input/output in CLI mode (#31) Summary: `php://input` is never a real file handle, even in CLI mode. We should change this now we don't need to be PHP-compatible, but for now, workaround it by exposing the real STDIN. This demonstrates the diference: ``` > function request_output(): WriteHandle { + // php://output has differing eof behavior for interactive stdin - we need + // the php://stdout for interactive usage (e.g. repls) + /* HH_IGNORE_ERROR[2049] __PHPStdLib */ + /* HH_IGNORE_ERROR[4107] __PHPStdLib */ + if (\php_sapi_name() === "cli") { + return server_output(); + } return _Private\StdioHandle::requestOutput(); } @@ -66,6 +74,14 @@ function request_error(): WriteHandle { * In CLI mode, this is likely STDIN; for HTTP requests, it may contain the * POST data, if any. */ +<<__Memoize>> function request_input(): ReadHandle { + // php://input has differing eof behavior for interactive stdin - we need + // the php://stdin for interactive usage (e.g. repls) + /* HH_IGNORE_ERROR[2049] __PHPStdLib */ + /* HH_IGNORE_ERROR[4107] __PHPStdLib */ + if (\php_sapi_name() === "cli") { + return server_input(); + } return _Private\StdioHandle::requestInput(); }