-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathOutput.php
More file actions
50 lines (43 loc) · 1.23 KB
/
Output.php
File metadata and controls
50 lines (43 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace PHPJava\IO\Standard;
use PHPJava\Core\JVM\Parameters\GlobalOptions;
use PHPJava\Core\JVM\Parameters\Runtime;
final class Output
{
private static $outputHeapspace = '';
private static function getOutputHandler()
{
static $outputHandle;
if ($outputHandle === null) {
$outputHandle = fopen(
GlobalOptions::get('output.handler') ?? Runtime::OUTPUT_HANDLER,
'rw+'
);
}
return $outputHandle;
}
public static function write(...$texts): void
{
if ((GlobalOptions::get('output.heapspace') ?? Runtime::OUTPUT_HEAPSPACE) === true) {
foreach ($texts as $text) {
static::$outputHeapspace .= (string) $text;
}
}
foreach ($texts as $text) {
fwrite(static::getOutputHandler(), (string) $text);
}
}
public static function clearHeapspace()
{
static::$outputHeapspace = '';
}
public static function getHeapspace(bool $clearHeapspace = true): string
{
$return = static::$outputHeapspace;
if ($clearHeapspace) {
static::clearHeapspace();
}
return $return;
}
}