-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreload.php
More file actions
56 lines (48 loc) · 1.12 KB
/
preload.php
File metadata and controls
56 lines (48 loc) · 1.12 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
51
52
53
54
55
56
<?php
// TODO:
// find a way to set the preload_user dynamically,
// then add to the ini file,
// and inject the PHP_VERSION into the preload.php file.
$paths = [
[
'dir' => '/var/odigos/php/${PHP_VERSION}/',
'include' => [],
'exclude' => [
'.phan',
'.php-cs-fixer',
'Composer',
'composer',
'Tests',
'tests',
'Test',
'test',
],
],
];
if (!extension_loaded('opentelemetry')) {
echo 'OpenTelemetry extension not loaded' . PHP_EOL;
return;
}
foreach ($paths as $path) {
$directory = new RecursiveDirectoryIterator($path['dir']);
$fullTree = new RecursiveIteratorIterator($directory);
$phpFiles = new RegexIterator(
$fullTree,
'/.+((?<!Test)+\.php$)/i',
RecursiveRegexIterator::GET_MATCH
);
foreach ($phpFiles as $key => $file) {
$filename = $file[0];
foreach ($path['exclude'] as $exclude) {
if (str_contains($filename, $exclude)) {
continue 2;
}
}
foreach ($path['include'] as $include) {
if (!str_contains($filename, $include)) {
continue 2;
}
}
require_once $filename;
}
}