This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
forked from vanilla/vanilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.php
60 lines (55 loc) · 2.11 KB
/
preload.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
<?php
/**
* @author Adam Charron <[email protected]>
* @copyright 2009-2022 Vanilla Forums Inc.
* @license Proprietary
*/
use Vanilla\AddonManager;
define("PATH_ROOT", realpath(__DIR__));
require PATH_ROOT . "/environment.php";
// Loadup library
$dirs = ["/library"];
foreach ($dirs as $dir) {
$directory = new RecursiveDirectoryIterator(PATH_ROOT . $dir);
$fullTree = new RecursiveIteratorIterator($directory);
$phpFiles = new RegexIterator($fullTree, '/.+((?<!Test)+\.php$)/i', RecursiveRegexIterator::GET_MATCH);
foreach ($phpFiles as $key => $file) {
if (
// Make sure we don't load any files that declare global functions or have side effects.
str_contains($file[0], "/views/") ||
str_contains($file[0], "/settings/") ||
str_contains($file[0], "functions.") ||
str_contains($file[0], "bootstrap") ||
// Smarty is not compatible with preload because it autoloads pretty weirdly.
// Essentially it's main class defines a bunch of constants that never get recreated if the classes were preloaded.
str_contains(strtolower($file[0]), "smarty")
) {
continue;
}
require_once $file[0];
}
}
// Loadup addons.
$addonManager = new AddonManager(AddonManager::getDefaultScanDirectories(), PATH_CACHE);
$addonManager->preloadAddonClasses([
// It's very important that none of the classes here declare any global functions inside of their class declarations.
// If that is the case the function will be loaded permanently and take precedence at runtime, even if the addon is not enabled.
//
// If you are going to add more, validate the following.
// - Class declarations in that plugin do not have sideeffects outside of the class declaration.
// - Nothing is doing class_exists() checks to determine if the plugin is loaded.
"dashboard",
"vanilla",
"conversations",
"groups",
"knowledge",
"vanillaanalytics",
"Reactions",
"ideation",
"webhooks",
"elasticsearch",
"hosted-job",
"themingapi",
"badges",
"QnA",
]);