Changeset View
Changeset View
Standalone View
Standalone View
src/utils/PhutilSystem.php
<?php | <?php | ||||
/** | /** | ||||
* Interact with the operating system. | * Interact with the operating system. | ||||
* | * | ||||
* @task stdio Interacting with Standard I/O | |||||
* @task memory Interacting with System Memory | * @task memory Interacting with System Memory | ||||
*/ | */ | ||||
final class PhutilSystem extends Phobject { | final class PhutilSystem extends Phobject { | ||||
private static $stdin = false; | |||||
private static $stderr = false; | |||||
private static $stdout = false; | |||||
/** | |||||
* @task stdio | |||||
*/ | |||||
public static function getStdinHandle() { | |||||
if (self::$stdin === false) { | |||||
self::$stdin = self::getStdioHandle('STDIN'); | |||||
} | |||||
return self::$stdin; | |||||
} | |||||
/** | |||||
* @task stdio | |||||
*/ | |||||
public static function getStdoutHandle() { | |||||
if (self::$stdout === false) { | |||||
self::$stdout = self::getStdioHandle('STDOUT'); | |||||
} | |||||
return self::$stdout; | |||||
} | |||||
/** | |||||
* @task stdio | |||||
*/ | |||||
public static function getStderrHandle() { | |||||
if (self::$stderr === false) { | |||||
self::$stderr = self::getStdioHandle('STDERR'); | |||||
} | |||||
return self::$stderr; | |||||
} | |||||
/** | |||||
* @task stdio | |||||
*/ | |||||
public static function writeStderr($message) { | |||||
$stderr = self::getStderrHandle(); | |||||
if ($stderr === null) { | |||||
return; | |||||
} | |||||
$message = phutil_string_cast($message); | |||||
@fwrite($stderr, $message); | |||||
} | |||||
/** | |||||
* @task stdio | |||||
*/ | |||||
private static function getStdioHandle($ref) { | |||||
if (defined($ref)) { | |||||
return constant($ref); | |||||
} | |||||
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 147 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0