Allow namespace in auto loader (#7307)

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove class_exists wrapper for class definitions

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove include statement of class file

* remove closing tag

* remove invalid method params

* remove closing tag

* remove closing tag

* Update auto_loader to load each class file in the project
Update the auto_loader class to use an include statement on each file in the project to load the class within the file. This will allow mismatched names within the file to be loaded and mapped according to the declaration instead of the filename. The class is then checked against the parsed classes from the PHP engine so that namespaces are available and mapped to the file they were declared in. An update was also made to the search algorithm used to find a file that was not already loaded by collapsing the array to have only valid matches to increase performance on a cache miss. Logging within the auto_loader has been moved to a function.
Multiple files were modified to allow the include statement. When the class has the `if(class_exists())` statement, the auto_loader is called to check for the class. This caused an infinite loop scenario so all wrappers have been removed. The auto_loader will now break the loop by directly modifying the internal classes array instead of trying to restart with the 'reload_classes' method.

- APCu is used to cache classes so any loading of the classes is done only once. To clear the APCu cache, restart php-fpm or call the auto_loader::clear_cache() function.
- Cache file is used when APCu is not available. To clear the cache remove it from the tmp folder or call the auto_loader::clear_cache() function.
- All classes must no longer have a class_exists wrapper to benefit from the performance boost.
- Classes should not be directly included when the auto_loader is used.

* remove include statement of class file

* Update destinations.php
This commit is contained in:
frytimo
2025-03-12 13:55:47 -06:00
committed by GitHub
parent abb95e38bb
commit 08001488f4
110 changed files with 209 additions and 520 deletions
@@ -96,7 +96,6 @@ class authentication {
//process the plugin
if (file_exists($plugin)) {
//run the plugin
include_once $plugin;
$object = new $class_name();
$object->domain_name = $this->domain_name;
$object->domain_uuid = $this->domain_uuid;
@@ -26,8 +26,6 @@
/**
* plugin_email
*
* @method email time based one time password authenticate the user
*/
class plugin_email {
@@ -521,5 +519,3 @@ class plugin_email {
}
}
?>
@@ -209,5 +209,3 @@ class plugin_ldap {
return $result;
}
}
?>
@@ -439,5 +439,3 @@ class plugin_totp {
}
}
?>
-1
View File
@@ -42,7 +42,6 @@ if (!empty($_GET)) {
$text = $language->get();
//create the vcard object
require_once "resources/classes/vcard.php";
$vcard = new vcard();
//get the contact id
@@ -25,7 +25,6 @@
*/
//define the contacts class
if (!class_exists('contacts')) {
class contacts {
const APP_NAME = "contacts";
@@ -277,6 +276,3 @@ if (!class_exists('contacts')) {
} //method
} //class
}
?>
@@ -26,12 +26,7 @@
/**
* dashboard class
*
* @method null delete
* @method null toggle
* @method null copy
*/
if (!class_exists('dashboard')) {
class dashboard {
/**
@@ -247,6 +242,3 @@ if (!class_exists('dashboard')) {
}
}
}
?>
@@ -25,7 +25,6 @@
*/
//define the databases class
if (!class_exists('databases')) {
class databases {
/**
@@ -169,6 +168,3 @@ if (!class_exists('databases')) {
}
}
}
?>
@@ -26,12 +26,7 @@
/**
* default_settings class
*
* @method null delete
* @method null toggle
* @method null copy
*/
if (!class_exists('default_settings')) {
class default_settings {
/**
@@ -327,6 +322,3 @@ if (!class_exists('default_settings')) {
} //method
} //class
}
?>
@@ -25,7 +25,6 @@
*/
//define the domain settings class
if (!class_exists('domain_settings')) {
class domain_settings {
/**
@@ -386,6 +385,3 @@ if (!class_exists('domain_settings')) {
} //method
} //class
}
?>
-1
View File
@@ -486,7 +486,6 @@
//recreate dialplan and extension xml files
if (is_readable($_SESSION['switch']['extensions']['dir'])) {
require_once $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/extensions/resources/classes/extension.php";
$extension = new extension;
$extension->xml();
}
@@ -25,7 +25,6 @@
*/
//define the email templates class
if (!class_exists('email_templates')) {
class email_templates {
/**
@@ -244,6 +243,3 @@ if (!class_exists('email_templates')) {
}
}
}
?>
+1 -8
View File
@@ -2,9 +2,6 @@
/**
* events class provides an event system
*
* @method void load_plugins
* @method dynamic __call
*/
class events {
@@ -31,11 +28,7 @@ class events {
//create the database connection
//includes files
require_once dirname(__DIR__, 4) . "/resources/require.php";
//includes files
require_once "resources/classes/database.php";
$database = new database;
$database = database::new();
$database->connect();
$this->db = $database->db;
return $this->db = $database->db;
-1
View File
@@ -43,7 +43,6 @@
$text = $language->get();
//permission restore default
require_once "core/groups/resources/classes/permission.php";
$permission = new permission;
$permission->restore();
+1 -5
View File
@@ -1,6 +1,5 @@
<?php
if (!class_exists('install')) {
class install {
/**
@@ -154,7 +153,7 @@ if (!class_exists('install')) {
if(!$file_handle) { return; }
fwrite($file_handle, $conf);
fclose($file_handle);
//if the config.conf file was saved return true
if (file_exists($config_file)) {
return true;
@@ -166,6 +165,3 @@ if (!class_exists('install')) {
}
}
}
?>
-1
View File
@@ -51,7 +51,6 @@
}
//menu restore default
//require_once "resources/classes/menu.php";
$menu = new menu;
$menu->menu_uuid = $menu_uuid;
$menu->menu_language = $menu_language;
@@ -2,10 +2,7 @@
/**
* software class
*
* @method string version
*/
if (!class_exists('software')) {
class software {
/**
@@ -25,6 +22,3 @@ if (!class_exists('software')) {
}
}
}
?>
-1
View File
@@ -133,7 +133,6 @@
//load an array of the database schema and compare it with the active database
if (!empty($action["upgrade_schema"]) && permission_exists("upgrade_schema")) {
require_once "resources/classes/schema.php";
$obj = new schema();
if (isset($action["data_types"]) && $action["data_types"] == 'true') {
$obj->data_types = true;
-3
View File
@@ -189,8 +189,6 @@
//run all app_defaults.php files
if ($upgrade_type == 'domains') {
require_once "resources/classes/config.php";
require_once "resources/classes/domains.php";
$domain = new domains;
$domain->display_type = $display_type;
$domain->upgrade();
@@ -199,7 +197,6 @@
//upgrade schema and/or data_types
if ($upgrade_type == 'schema') {
//get the database schema put it into an array then compare and update the database as needed.
require_once "resources/classes/schema.php";
$obj = new schema;
if (isset($argv[2]) && $argv[2] == 'data_types') {
$obj->data_types = true;
-2
View File
@@ -46,8 +46,6 @@
}
//run all app_defaults.php files
require_once "resources/classes/config.php";
require_once "resources/classes/domains.php";
$domain = new domains;
$domain->display_type = $display_type;
$domain->upgrade();
-3
View File
@@ -273,8 +273,6 @@ function do_upgrade_code_submodules() {
* Execute all app_defaults.php files
*/
function do_upgrade_domains() {
require_once dirname(__DIR__, 2) . "/resources/classes/config.php";
require_once dirname(__DIR__, 2) . "/resources/classes/domains.php";
$domain = new domains;
$domain->display_type = 'text';
$domain->upgrade();
@@ -285,7 +283,6 @@ function do_upgrade_domains() {
*/
function do_upgrade_schema(bool $data_types = false) {
//get the database schema put it into an array then compare and update the database as needed.
require_once dirname(__DIR__, 2) . "/resources/classes/schema.php";
$obj = new schema;
$obj->data_types = $data_types;
echo $obj->schema('text');
-1
View File
@@ -59,7 +59,6 @@
$text = $language->get();
//get the database schema put it into an array then compare and update the database as needed.
require_once "resources/classes/schema.php";
$obj = new schema;
if (isset($argv[1]) && $argv[1] == 'data_types') {
$obj->data_types = true;
@@ -26,12 +26,7 @@
/**
* user_logs class
*
* @method null delete
* @method null toggle
* @method null copy
*/
if (!class_exists('user_logs')) {
class user_logs {
/**
@@ -151,6 +146,3 @@ if (!class_exists('user_logs')) {
}
}
}
?>
@@ -25,7 +25,6 @@
*/
//define the user settings class
if (!class_exists('user_settings')) {
class user_settings {
/**
@@ -181,6 +180,3 @@ if (!class_exists('user_settings')) {
} //method
} //class
}
?>
-1
View File
@@ -107,7 +107,6 @@ Mark J Crane <markjcrane@fusionpbx.com>
//revoke temporary permissions
$p->delete('user_setting_delete', 'temp');
//reset session variables to default
require "resources/classes/domains.php";
$domain = new domains();
$domain->set();
}
-8
View File
@@ -26,12 +26,7 @@
/**
* users class
*
* @method null delete
* @method null toggle
* @method null copy
*/
if (!class_exists('users')) {
class users {
/**
@@ -315,6 +310,3 @@ if (!class_exists('users')) {
}
}
}
}
?>