Changeset View
Changeset View
Standalone View
Standalone View
src/utils/PhutilSystem.php
| Show All 11 Lines | final class PhutilSystem extends Phobject { | ||||
| private static $stderr = false; | private static $stderr = false; | ||||
| private static $stdout = false; | private static $stdout = false; | ||||
| /** | /** | ||||
| * @task stdio | * @task stdio | ||||
| */ | */ | ||||
| public static function getStdinHandle() { | public static function getStdinHandle() { | ||||
| if (self::$stdin === false) { | if (self::$stdin === false) { | ||||
| self::$stdin = self::newStdioHandle('php://stdin'); | self::$stdin = self::getStdioHandle('STDIN'); | ||||
| } | } | ||||
| return self::$stdin; | return self::$stdin; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task stdio | * @task stdio | ||||
| */ | */ | ||||
| public static function getStdoutHandle() { | public static function getStdoutHandle() { | ||||
| if (self::$stdout === false) { | if (self::$stdout === false) { | ||||
| self::$stdout = self::newStdioHandle('php://stdout'); | self::$stdout = self::getStdioHandle('STDOUT'); | ||||
| } | } | ||||
| return self::$stdout; | return self::$stdout; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task stdio | * @task stdio | ||||
| */ | */ | ||||
| public static function getStderrHandle() { | public static function getStderrHandle() { | ||||
| if (self::$stderr === false) { | if (self::$stderr === false) { | ||||
| self::$stderr = self::newStdioHandle('php://stderr'); | self::$stderr = self::getStdioHandle('STDERR'); | ||||
| } | } | ||||
| return self::$stderr; | return self::$stderr; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task stdio | * @task stdio | ||||
| */ | */ | ||||
| public static function writeStderr($message) { | public static function writeStderr($message) { | ||||
| $stderr = self::getStderrHandle(); | $stderr = self::getStderrHandle(); | ||||
| if ($stderr === null) { | if ($stderr === null) { | ||||
| return; | return; | ||||
| } | } | ||||
| $message = phutil_string_cast($message); | $message = phutil_string_cast($message); | ||||
| @fwrite($stderr, $message); | @fwrite($stderr, $message); | ||||
| } | } | ||||
| /** | /** | ||||
| * @task stdio | * @task stdio | ||||
| */ | */ | ||||
| private static function newStdioHandle($ref) { | private static function getStdioHandle($ref) { | ||||
| $ignored_mode = ''; | if (defined($ref)) { | ||||
| return constant($ref); | |||||
| $handle = @fopen($ref, $ignored_mode); | |||||
| if ($handle === false) { | |||||
| return null; | |||||
| } | } | ||||
| return $handle; | return null; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get information about total and free memory on the system. | * Get information about total and free memory on the system. | ||||
| * | * | ||||
| * Because "free memory" is a murky concept, the interpretation of the values | * Because "free memory" is a murky concept, the interpretation of the values | ||||
| * returned from this method will vary from system to system and the numbers | * returned from this method will vary from system to system and the numbers | ||||
| * themselves may be only roughly accurate. | * themselves may be only roughly accurate. | ||||
| ▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines | |||||