-
Notifications
You must be signed in to change notification settings - Fork 2
/
ffi_preloader.php
73 lines (63 loc) · 2.47 KB
/
ffi_preloader.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
<?php
declare(strict_types=1);
if (!\function_exists('ffi_preloader')) {
if (!\defined('DS'))
\define('DS', \DIRECTORY_SEPARATOR);
function ffi_preloader(): void
{
if (!\function_exists('zend_preloader') || !\class_exists('Core'))
include_once '..' . \DS . 'vendor' . \DS . 'symplely' . \DS . 'zend-ffi' . \DS . 'preload.php';
if (!\file_exists('.' . \DS . 'ffi_generated.json')) {
$directories = \glob('*', \GLOB_ONLYDIR);
$directory = $files = [];
foreach ($directories as $ffi_dir) {
if (\file_exists($ffi_dir . \DS . 'ffi_extension.json')) {
$ffi_list = \json_decode(\file_get_contents($ffi_dir . \DS . 'ffi_extension.json'), true);
if (isset($ffi_list['preload']['directory'])) {
\array_push($directory, $ffi_list['preload']['directory']);
} elseif (isset($ffi_list['preload']['files'])) {
\array_push($files, $ffi_list['preload']['files']);
}
}
}
\file_put_contents(
'.' . \DS . 'ffi_generated.json',
\json_encode([
"preload" => [
"files" => $files,
"directory" => $directory
]
], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES)
);
}
if (\file_exists('.' . \DS . 'ffi_generated.json')) {
$loader = function ($iterator, bool $isDir, bool $is_opcache_cli) {
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;
}
}
};
$preload_list = \json_decode(\file_get_contents('.' . \DS . 'ffi_generated.json'), true);
$is_opcache_cli = \ini_get('opcache.enable_cli') === '1';
if (isset($preload_list['preload']['files'])) {
$loader($preload_list['preload']['files'], false, $is_opcache_cli);
}
if (isset($preload_list['preload']['directory'])) {
foreach ($preload_list['preload']['directory'] as $directory) {
$dir = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::KEY_AS_PATHNAME);
$iterator = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
$loader($iterator, true, $is_opcache_cli);
}
}
}
}
\ffi_preloader();
}