-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy patherror_handle.php
42 lines (33 loc) · 892 Bytes
/
error_handle.php
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
<?php
declare(strict_types=1);
namespace Psl\IO;
use Revolt\EventLoop;
use WeakMap;
use const PHP_SAPI;
/**
* 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.
*
* @codeCoverageIgnore
*/
function error_handle(): null|CloseWriteStreamHandleInterface
{
/** @var WeakMap|null $cache */
static $cache = null;
if (null === $cache) {
$cache = new WeakMap();
}
$key = EventLoop::getDriver();
if ($cache->offsetExists($key)) {
/** @var CloseWriteStreamHandleInterface|null */
return $cache->offsetGet($key);
}
$handle = null;
if (PHP_SAPI === 'cli') {
$handle = new CloseWriteStreamHandle(Internal\open_resource('php://stderr', 'wb'));
}
$cache->offsetSet($key, $handle);
return $handle;
}