Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Commit

Permalink
Revert "Remove stdout/stderr/stdin, add {request,server}{Output,Input…
Browse files Browse the repository at this point in the history
…,Error}"

This reverts commit e9463c3.
  • Loading branch information
fredemmott committed Dec 5, 2018
1 parent e9463c3 commit 336dacb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 100 deletions.
20 changes: 0 additions & 20 deletions src/io/InvalidHandleException.php

This file was deleted.

34 changes: 6 additions & 28 deletions src/io/_Private/StdioHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,17 @@

final class StdioHandle extends NativeHandle {
<<__Memoize>>
public static function serverError(): IO\WriteHandle {
// while the documentation says to use the STDERR constant, that is
// conditionally defined
return new self(\fopen('php://stderr', 'w'));
public static function stderr(): IO\WriteHandle {
return new self(\STDERR);
}

<<__Memoize>>
public static function serverOutput(): IO\WriteHandle {
return new self(\fopen('php://stdout', 'w'));
public static function stdout(): IO\WriteHandle {
return new self(\STDOUT);
}

<<__Memoize>>
public static function serverInput(): IO\ReadHandle {
return new self(\fopen('php://stdin', 'r'));
}

<<__Memoize>>
public static function requestInput(): IO\ReadHandle {
return new self(\fopen('php://input', 'r'));
}

<<__Memoize>>
public static function requestOutput(): IO\WriteHandle{
return new self(\fopen('php://output', 'r'));
}

<<__Memoize>>
public static function requestError(): IO\WriteHandle {
if (\php_sapi_name() !== "cli") {
throw new IO\InvalidHandleException(
"requestError is not supported in the current execution mode"
);
}
return self::serverError();
public static function stdin(): IO\ReadHandle {
return new self(\STDIN);
}
}
58 changes: 6 additions & 52 deletions src/io/stdio.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,14 @@

use namespace HH\Lib\_Private;

/** Return STDOUT for the server process.
*
* This is usually not the same thing as request output.
*
* @see requestOutput
*/
function serverOutput(): WriteHandle {
return _Private\StdioHandle::serverOutput();
function stdout(): WriteHandle {
return _Private\StdioHandle::stdout();
}

/** Return STDERR for the server process.
*
* @see requestError
*/
function serverError(): WriteHandle {
return _Private\StdioHandle::serverError();
function stderr(): WriteHandle {
return _Private\StdioHandle::stderr();
}

/** Return STDIN for the server process.
*
* @see requestInput
*/
function serverInput(): ReadHandle {
return _Private\StdioHandle::serverInput();
}

/** Return the output handle for the current request.
*
* This should generally be used for sending data to clients. In CLI mode, this
* is usually the process STDOUT.
*
* @see requestOutput
*/
function requestOutput(): WriteHandle {
return _Private\StdioHandle::requestOutput();
}

/** Return the error output handle for the current request.
*
* This is usually only available for CLI scripts; it will throw an
* `UnsupportedHandleException` in most other contexts, including HTTP
* requests.
*
* In CLI mode, this is usually the process STDERR.
*/
function requestError(): WriteHandle {
return _Private\StdioHandle::requestError();
}

/** Return the input handle for the current request.
*
* In CLI mode, this is likely STDIN; for HTTP requests, it may contain the
* POST data, if any.
*/
function requestInput(): ReadHandle {
return _Private\StdioHandle::requestInput();
function stdin(): ReadHandle {
return _Private\StdioHandle::stdin();
}

0 comments on commit 336dacb

Please sign in to comment.