-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobal.php
108 lines (93 loc) · 3.03 KB
/
global.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* @author Mohammed Moussaoui
* @license MIT license. For more license information, see the LICENSE file in the root directory.
* @link https://github.com/DevNet-Framework
*/
namespace DevNet\System {
use DevNet\System\Async\AsyncFunction;
use DevNet\System\Async\IAwaitable;
use DevNet\System\Diagnostics\Debug;
use DevNet\System\Exceptions\ArrayException;
use DevNet\System\Type;
use Fiber;
function async(callable $action): AsyncFunction
{
return new AsyncFunction($action);
}
function await(IAwaitable $awaitable): mixed
{
$awaitable = Fiber::suspend($awaitable);
return $awaitable->getAwaiter()->getResult();
};
function typeOf(string $typeName, array $typeArguments = []): Type
{
try {
$type = new Type($typeName, $typeArguments);
} catch (ArrayException $exception) {
throw new ArrayException($exception->getMessage(), $exception->getCode(), 1);
}
return $type;
}
function debug($value = null): Debug
{
$debug = Debug::getInstance();
if (func_num_args()) {
$time = \DateTime::createFromFormat('U.u', microtime(TRUE));
$debug->write('[' . $time->format('H:i:s.v') . '] ');
$debug->writeLine($value, 'Debug');
$debug->indent();
$debug->write('at ');
$debug->caller(1);
$debug->unindent();
}
return $debug;
}
}
namespace {
use DevNet\System\Async\AsyncFunction;
use DevNet\System\Async\IAwaitable;
use DevNet\System\Diagnostics\Debug;
use DevNet\System\Exceptions\ArrayException;
use DevNet\System\Type;
if (!function_exists("async")) {
function async(callable $action): AsyncFunction
{
return new AsyncFunction($action);
}
}
if (!function_exists("await")) {
function await(IAwaitable $awaitable): mixed
{
$awaitable = Fiber::suspend($awaitable);
return $awaitable->getAwaiter()->getResult();
};
}
if (!function_exists("typeOf")) {
function typeOf(string $typeName, array $typeArguments = []): Type
{
try {
$type = new Type($typeName, $typeArguments);
} catch (ArrayException $exception) {
throw new ArrayException($exception->getMessage(), $exception->getCode(), 1);
}
return $type;
}
}
if (!function_exists("debug")) {
function debug($value = null): Debug
{
$debug = Debug::getInstance();
if (func_num_args()) {
$time = \DateTime::createFromFormat('U.u', microtime(TRUE));
$debug->write('[' . $time->format('H:i:s.v') . '] ');
$debug->writeLine($value, 'Debug');
$debug->indent();
$debug->write('at ');
$debug->caller(1);
$debug->unindent();
}
return $debug;
}
}
}