Centralize class loader (#4169)

Move the classloader to as early as possible in defaults.inc.php
This should cover all application entrances.
Set install_dir based on the location of defaults.inc.php
This commit is contained in:
Tony Murray
2016-08-22 17:59:59 -05:00
committed by Neil Lathwood
parent e920e28e48
commit 7b93b564da
6 changed files with 15 additions and 41 deletions

View File

@@ -24,7 +24,6 @@
error_reporting(E_ERROR|E_PARSE|E_CORE_ERROR|E_COMPILE_ERROR);
function set_debug($debug) {
if (isset($debug)) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
@@ -32,15 +31,26 @@ function set_debug($debug) {
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
}
}//end set_debug()
// set install_dir
$config['install_dir'] = realpath(__DIR__ . '/..');
// initialize the class loader and add custom mappings
require_once $config['install_dir'] . '/LibreNMS/ClassLoader.php';
$classLoader = new LibreNMS\ClassLoader();
$classLoader->registerClass('Console_Color2', $config['install_dir'] . '/includes/console_colour.php');
$classLoader->registerClass('Console_Table', $config['install_dir'] . '/includes/console_table.php');
$classLoader->registerClass('PHPMailer', $config['install_dir'] . "/includes/phpmailer/class.phpmailer.php");
$classLoader->registerClass('SMTP', $config['install_dir'] . "/includes/phpmailer/class.smtp.php");
$classLoader->registerClass('PasswordHash', $config['install_dir'] . '/html/lib/PasswordHash.php');
$classLoader->register();
// Default directories
$config['project_name'] = 'LibreNMS';
$config['project_id'] = strtolower($config['project_name']);
$config['temp_dir'] = '/tmp';
$config['install_dir'] = '/opt/'.$config['project_id'];
$config['log_dir'] = $config['install_dir'].'/logs';
// MySQL extension to use