-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpreload_skeleton.php
71 lines (62 loc) · 1.92 KB
/
preload_skeleton.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
<?php
declare(strict_types=1);
if (!\function_exists('tag_changeMe_preload')) {
/**
* Check for _active_ `tag_changeMe` **ffi** instance
*
* @return boolean
*/
function is_tag_changeMe_ffi(): bool
{
return Core::get('tag_changeMe') instanceof \FFI;
}
function tag_changeMe_ffi(): \FFI
{
return Core::get('tag_changeMe');
}
function tag_changeMe_init(): void
{
if (!\is_tag_changeMe_ffi()) {
// Try if preloaded
try {
Core::set('tag_changeMe', \FFI::scope("_tag_changeMe_"));
} catch (Exception $e) {
\tag_changeMe_preload();
}
if (!\is_tag_changeMe_ffi()) {
throw new \RuntimeException("FFI parse failed!");
}
}
}
function tag_changeMe_preload(): void
{
\setup_ffi_loader('tag_changeMe', 'filepath_to_headers');
if (\file_exists('.' . \DS . 'ffi_extension.json')) {
$ext_list = \json_decode(\file_get_contents('.' . \DS . 'ffi_extension.json'), true);
$isDir = false;
$iterator = [];
$is_opcache_cli = \ini_get('opcache.enable_cli') === '1';
if (isset($ext_list['preload']['directory'])) {
$isDir = true;
$directory = \array_shift($ext_list['preload']['directory']);
$dir = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::KEY_AS_PATHNAME);
$iterator = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
} elseif (isset($ext_list['preload']['files'])) {
$iterator = $ext_list['preload']['files'];
}
foreach ($iterator as $fileInfo) {
if ($isDir && !$fileInfo->isFile()) {
continue;
}
$file = $isDir ? $fileInfo->getPathname() : $fileInfo;
if ($is_opcache_cli) {
if (!\opcache_is_script_cached($file))
\opcache_compile_file($file);
} else {
include_once $file;
}
}
}
}
\tag_changeMe_preload();
}