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 16:55:47 -03:00 committed by GitHub
parent abb95e38bb
commit 08001488f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
110 changed files with 209 additions and 520 deletions

View File

@ -2,11 +2,7 @@
/** /**
* access controls class * access controls class
*
* @method null download
*/ */
if (!class_exists('access_controls')) {
class access_controls { class access_controls {
/** /**
@ -264,6 +260,3 @@ if (!class_exists('access_controls')) {
} }
} }
} }
}
?>

View File

@ -27,7 +27,6 @@
/** /**
* Define the operator_panel class * Define the operator_panel class
*/ */
if (!class_exists('basic_operator_panel')) {
class basic_operator_panel { class basic_operator_panel {
/** /**
@ -245,6 +244,3 @@ if (!class_exists('basic_operator_panel')) {
return $result; return $result;
} }
} }
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the bridges class //define the bridges class
if (!class_exists('bridges')) {
class bridges { class bridges {
/** /**
@ -255,6 +254,3 @@ if (!class_exists('bridges')) {
} }
} }
}
?>

View File

@ -2,10 +2,7 @@
/** /**
* call block class * call block class
*
* @method null download
*/ */
if (!class_exists('call_block')) {
class call_block { class call_block {
/** /**
@ -459,6 +456,3 @@ if (!class_exists('call_block')) {
} //method } //method
} //class } //class
}
?>

View File

@ -27,10 +27,7 @@
/** /**
* call broadcast class * call broadcast class
*
* @method null download
*/ */
if (!class_exists('call_broadcast')) {
class call_broadcast { class call_broadcast {
/** /**
@ -177,6 +174,3 @@ if (!class_exists('call_broadcast')) {
} }
} }
}
?>

View File

@ -26,11 +26,8 @@
/** /**
* cache class provides an abstracted cache * cache class provides an abstracted cache
*
* @method string dialplan - builds the dialplan for call center
*/ */
//define the call center class //define the call center class
if (!class_exists('call_center')) {
class call_center { class call_center {
/** /**
* define the variables * define the variables
@ -611,7 +608,6 @@
} //method } //method
} //class } //class
}
/* /*
$o = new call_center; $o = new call_center;
@ -625,5 +621,3 @@ $c->destination_number = "";
$c->queue_cc_exit_keys = ""; $c->queue_cc_exit_keys = "";
$c->dialplan(); $c->dialplan();
*/ */
?>

View File

@ -27,8 +27,7 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;
//check permisions //check permisions

View File

@ -25,7 +25,6 @@
*/ */
//define the call_flows class //define the call_flows class
if (!class_exists('call_flows')) {
class call_flows { class call_flows {
/** /**
@ -410,6 +409,3 @@ if (!class_exists('call_flows')) {
} //method } //method
} //class } //class
}
?>

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -421,7 +421,6 @@
//synchronize configuration //synchronize configuration
if (!empty($_SESSION['switch']['extensions']['dir']) && is_readable($_SESSION['switch']['extensions']['dir'])) { if (!empty($_SESSION['switch']['extensions']['dir']) && is_readable($_SESSION['switch']['extensions']['dir'])) {
require_once "app/extensions/resources/classes/extension.php";
$ext = new extension; $ext = new extension;
$ext->xml(); $ext->xml();
unset($ext); unset($ext);

View File

@ -248,7 +248,6 @@
//synchronize configuration //synchronize configuration
if (!empty($_SESSION['switch']['extensions']['dir']) && is_readable($_SESSION['switch']['extensions']['dir'])) { if (!empty($_SESSION['switch']['extensions']['dir']) && is_readable($_SESSION['switch']['extensions']['dir'])) {
require_once "app/extensions/resources/classes/extension.php";
$ext = new extension; $ext = new extension;
$ext->xml(); $ext->xml();
unset($ext); unset($ext);

View File

@ -261,7 +261,6 @@
//synchronize configuration //synchronize configuration
if (!empty($_SESSION['switch']['extensions']['dir']) && is_readable($_SESSION['switch']['extensions']['dir'])) { if (!empty($_SESSION['switch']['extensions']['dir']) && is_readable($_SESSION['switch']['extensions']['dir'])) {
require_once "app/extensions/resources/classes/extension.php";
$ext = new extension; $ext = new extension;
$ext->xml(); $ext->xml();
unset($ext); unset($ext);

View File

@ -426,7 +426,6 @@
//synchronize configuration //synchronize configuration
if (!empty($_SESSION['switch']['extensions']['dir']) && is_readable($_SESSION['switch']['extensions']['dir'])) { if (!empty($_SESSION['switch']['extensions']['dir']) && is_readable($_SESSION['switch']['extensions']['dir'])) {
require_once "app/extensions/resources/classes/extension.php";
$ext = new extension; $ext = new extension;
$ext->xml(); $ext->xml();
unset($ext); unset($ext);

View File

@ -26,10 +26,7 @@
/** /**
* call_recordings class * call_recordings class
*
* @method null download
*/ */
if (!class_exists('call_recordings')) {
class call_recordings { class call_recordings {
/** /**
@ -525,6 +522,3 @@ if (!class_exists('call_recordings')) {
} }
} //class } //class
}
?>

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -26,7 +26,6 @@ Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
*/ */
//define the conference centers class //define the conference centers class
if (!class_exists('conference_centers')) {
class conference_centers { class conference_centers {
/** /**
@ -800,7 +799,7 @@ if (!class_exists('conference_centers')) {
} //class } //class
}
//example conference center //example conference center
/* /*
@ -814,5 +813,3 @@ if (!class_exists('conference_centers')) {
$result = $conference_center->rooms(); $result = $conference_center->rooms();
print_r($result); print_r($result);
*/ */
?>

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -26,12 +26,7 @@
/** /**
* conference_controls class * conference_controls class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('conference_controls')) {
class conference_controls { class conference_controls {
/** /**
@ -426,6 +421,3 @@ if (!class_exists('conference_controls')) {
} }
} }
}
?>

View File

@ -26,12 +26,7 @@
/** /**
* conference_profiles class * conference_profiles class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('conference_profiles')) {
class conference_profiles { class conference_profiles {
/** /**
@ -432,6 +427,3 @@ if (!class_exists('conference_profiles')) {
} }
} }
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the conferences class //define the conferences class
if (!class_exists('conferences')) {
class conferences { class conferences {
/** /**
@ -374,6 +373,3 @@ if (!class_exists('conferences')) {
} }
} }
}
?>

View File

@ -1964,7 +1964,6 @@
echo " ".$text['label-destination_hold_music']."\n"; echo " ".$text['label-destination_hold_music']."\n";
echo "</td>\n"; echo "</td>\n";
echo "<td width=\"70%\" class='vtable' align='left'>\n"; echo "<td width=\"70%\" class='vtable' align='left'>\n";
require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
$music_on_hold = new switch_music_on_hold; $music_on_hold = new switch_music_on_hold;
echo $music_on_hold->select('destination_hold_music', $destination_hold_music, null); echo $music_on_hold->select('destination_hold_music', $destination_hold_music, null);
echo " <br />\n"; echo " <br />\n";

View File

@ -26,11 +26,7 @@
/** /**
* destinations * destinations
*
* @method get_array get the destinations
* @method select build the html select
*/ */
if (!class_exists('destinations')) {
class destinations { class destinations {
/** /**
@ -455,26 +451,24 @@ if (!class_exists('destinations')) {
$destination_id = str_replace("[", "_", $destination_id); $destination_id = str_replace("[", "_", $destination_id);
//$destination_id = preg_replace('/[^a-zA-Z_,.]/', '', $destination_name); //$destination_id = preg_replace('/[^a-zA-Z_,.]/', '', $destination_name);
?> //send request for destinations
<script type="text/javascript"> echo "<script type=\"text/javascript\">\n";
function get_destinations(id, destination_type, action, search) { echo " function get_destinations(id, destination_type, action, search) {\n";
//alert(action); echo " var xhttp = new XMLHttpRequest();\n";
var xhttp = new XMLHttpRequest(); echo " xhttp.onreadystatechange = function() {\n";
xhttp.onreadystatechange = function() { echo " if (this.readyState == 4 && this.status == 200) {\n";
if (this.readyState == 4 && this.status == 200) { echo " document.getElementById(id).innerHTML = this.responseText;\n";
document.getElementById(id).innerHTML = this.responseText; echo " }\n";
} echo " };\n";
}; echo " if (action) {\n";
if (action) { echo " xhttp.open(\"GET\", \"/app/destinations/resources/destinations.php?destination_type=\"+destination_type+\"&action=\"+action, true);\n";
xhttp.open("GET", "/app/destinations/resources/destinations.php?destination_type="+destination_type+"&action="+action, true); echo " }\n";
} echo " else {\n";
else { echo " xhttp.open(\"GET\", \"/app/destinations/resources/destinations.php?destination_type=\"+destination_type, true);\n";
xhttp.open("GET", "/app/destinations/resources/destinations.php?destination_type="+destination_type, true); echo " }\n";
} echo " xhttp.send();\n";
xhttp.send(); echo " }\n";
} echo "</script>\n";
</script>
<?php
//get the destinations //get the destinations
$destinations = $this->get($destination_type); $destinations = $this->get($destination_type);
@ -1308,7 +1302,7 @@ if (!class_exists('destinations')) {
} //method } //method
} //class } //class
}
/* /*
$obj = new destinations; $obj = new destinations;
//$destinations = $obj->destinations; //$destinations = $obj->destinations;
@ -1319,5 +1313,3 @@ echo $obj->select('ivr', 'example4', '');
echo $obj->select('ivr', 'example5', ''); echo $obj->select('ivr', 'example5', '');
echo $obj->select('ivr', 'example6', ''); echo $obj->select('ivr', 'example6', '');
*/ */
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the dialplan class //define the dialplan class
if (!class_exists('dialplan')) {
class dialplan { class dialplan {
//variables //variables
@ -1580,6 +1579,3 @@
} //class } //class
}
?>

View File

@ -2,12 +2,7 @@
/** /**
* email_queue class * email_queue class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('email_queue')) {
class email_queue { class email_queue {
/** /**
@ -225,6 +220,3 @@ if (!class_exists('email_queue')) {
} }
} }
}
?>

View File

@ -11,7 +11,6 @@
//includes files //includes files
require_once "resources/pdo.php"; require_once "resources/pdo.php";
include "resources/classes/permissions.php";
require $_SERVER['DOCUMENT_ROOT']."/app/email_queue/resources/functions/transcribe.php"; require $_SERVER['DOCUMENT_ROOT']."/app/email_queue/resources/functions/transcribe.php";
//increase limits //increase limits

View File

@ -10,7 +10,6 @@
} }
//include files //include files
include "resources/classes/permissions.php";
include_once "resources/phpmailer/class.phpmailer.php"; include_once "resources/phpmailer/class.phpmailer.php";
include_once "resources/phpmailer/class.smtp.php"; include_once "resources/phpmailer/class.smtp.php";

View File

@ -9,9 +9,6 @@
exit; exit;
} }
//include files
include "resources/classes/permissions.php";
//increase limits //increase limits
set_time_limit(0); set_time_limit(0);
ini_set('max_execution_time', 0); ini_set('max_execution_time', 0);

View File

@ -26,12 +26,7 @@
/** /**
* event_guard_logs class * event_guard_logs class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('event_guard')) {
class event_guard { class event_guard {
/** /**
@ -303,6 +298,3 @@ if (!class_exists('event_guard')) {
} }
} }
}
?>

View File

@ -26,12 +26,7 @@
/** /**
* extension_settings class * extension_settings class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('extension_settings')) {
class extension_settings { class extension_settings {
/** /**
@ -272,6 +267,3 @@ if (!class_exists('extension_settings')) {
} }
} }
}
?>

View File

@ -186,7 +186,6 @@
//synchronize configuration //synchronize configuration
if (is_writable($_SESSION['switch']['extensions']['dir'])) { if (is_writable($_SESSION['switch']['extensions']['dir'])) {
require_once "app/extensions/resources/classes/extension.php";
$ext = new extension; $ext = new extension;
$ext->xml(); $ext->xml();
unset($ext); unset($ext);

View File

@ -850,7 +850,6 @@
//synchronize configuration //synchronize configuration
if (is_writable($switch_extensions)) { if (is_writable($switch_extensions)) {
require_once "app/extensions/resources/classes/extension.php";
$ext = new extension; $ext = new extension;
$ext->xml(); $ext->xml();
unset($ext); unset($ext);
@ -2037,7 +2036,6 @@
echo " ".$text['label-hold_music']."\n"; echo " ".$text['label-hold_music']."\n";
echo "</td>\n"; echo "</td>\n";
echo "<td width=\"70%\" class='vtable' align='left'>\n"; echo "<td width=\"70%\" class='vtable' align='left'>\n";
require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
$options = ''; $options = '';
$moh = new switch_music_on_hold; $moh = new switch_music_on_hold;
echo $moh->select('hold_music', $hold_music ?? '', $options); echo $moh->select('hold_music', $hold_music ?? '', $options);

View File

@ -25,7 +25,6 @@
*/ */
//define the directory class //define the directory class
if (!class_exists('extension')) {
class extension { class extension {
/** /**
@ -795,6 +794,3 @@ if (!class_exists('extension')) {
} }
} }
}
?>

View File

@ -29,7 +29,6 @@
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/functions/object_to_array.php"; require_once "resources/functions/object_to_array.php";
require_once "resources/functions/parse_message.php"; require_once "resources/functions/parse_message.php";
require_once "resources/classes/text.php";
//get accounts to monitor //get accounts to monitor
$sql = "select d.domain_name, f.* "; $sql = "select d.domain_name, f.* ";

View File

@ -25,7 +25,6 @@
*/ */
//define the fax class //define the fax class
if (!class_exists('fax')) {
class fax { class fax {
/** /**
@ -725,7 +724,6 @@ if (!class_exists('fax')) {
} }
} //class } //class
}
/* /*
$o = new fax; $o = new fax;
@ -738,5 +736,3 @@ $c->destination_number = $fax_destination_number;
$c->fax_description = $fax_description; $c->fax_description = $fax_description;
$c->dialplan(); $c->dialplan();
*/ */
?>

View File

@ -26,12 +26,7 @@
/** /**
* fax_queue class * fax_queue class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('fax_queue')) {
class fax_queue { class fax_queue {
/** /**
@ -274,6 +269,3 @@ if (!class_exists('fax_queue')) {
} }
} }
} }
}
?>

View File

@ -8,7 +8,6 @@
//includes files //includes files
require_once dirname(__DIR__, 4) . "/resources/require.php"; require_once dirname(__DIR__, 4) . "/resources/require.php";
require_once "resources/pdo.php"; require_once "resources/pdo.php";
include "resources/classes/permissions.php";
//increase limits //increase limits
set_time_limit(0); set_time_limit(0);

View File

@ -2,12 +2,7 @@
/** /**
* fifo class * fifo class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('fifo')) {
class fifo { class fifo {
/** /**
@ -283,6 +278,3 @@ if (!class_exists('fifo')) {
} }
} }
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the gateways class //define the gateways class
if (!class_exists('gateways')) {
class gateways { class gateways {
/** /**
@ -583,6 +582,3 @@ if (!class_exists('gateways')) {
} }
} }
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the ivr_menu class //define the ivr_menu class
if (!class_exists('ivr_menu')) {
class ivr_menu { class ivr_menu {
/** /**
@ -489,6 +488,3 @@ if (!class_exists('ivr_menu')) {
} }
} }
}
?>

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -25,7 +25,6 @@
*/ */
//define the modules class //define the modules class
if (!class_exists('modules')) {
class modules { class modules {
/** /**
@ -1101,10 +1100,8 @@ if (!class_exists('modules')) {
} //class } //class
}
/* /*
require_once "resources/classes/modules.php";
$mod = new modules; $mod = new modules;
$mod->dir = $_SESSION['switch']['mod']['dir']; $mod->dir = $_SESSION['switch']['mod']['dir'];
echo $mod->dir."\n"; echo $mod->dir."\n";
@ -1138,5 +1135,3 @@ echo $mod->dir."\n";
//print_r($result); //print_r($result);
//echo "</pre>\n"; //echo "</pre>\n";
*/ */
?>

View File

@ -308,7 +308,6 @@
$cache = new cache; $cache = new cache;
$cache->delete("configuration:local_stream.conf"); $cache->delete("configuration:local_stream.conf");
//require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
$music = new switch_music_on_hold; $music = new switch_music_on_hold;
$music->reload(); $music->reload();

View File

@ -27,7 +27,6 @@
*/ */
//define the switch_music_on_hold class //define the switch_music_on_hold class
if (!class_exists('switch_music_on_hold')) {
class switch_music_on_hold { class switch_music_on_hold {
/** /**
@ -85,7 +84,6 @@ if (!class_exists('switch_music_on_hold')) {
} }
//recordings //recordings
if (is_dir($_SERVER["PROJECT_ROOT"].'/app/recordings')) { if (is_dir($_SERVER["PROJECT_ROOT"].'/app/recordings')) {
require_once "app/recordings/resources/classes/switch_recordings.php";
$recordings_c = new switch_recordings; $recordings_c = new switch_recordings;
$recordings = $recordings_c->list_recordings(); $recordings = $recordings_c->list_recordings();
if (is_array($recordings) && sizeof($recordings) > 0) { if (is_array($recordings) && sizeof($recordings) > 0) {
@ -447,12 +445,9 @@ if (!class_exists('switch_music_on_hold')) {
} //method } //method
} //class } //class
}
//build and save the XML //build and save the XML
//require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
//$moh = new switch_music_on_hold; //$moh = new switch_music_on_hold;
//$moh->xml(); //$moh->xml();
//$moh->save(); //$moh->save();
?>

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -25,7 +25,6 @@
*/ */
//define the number translations class //define the number translations class
if (!class_exists('number_translations')) {
class number_translations { class number_translations {
/** /**
@ -414,11 +413,8 @@ if (!class_exists('number_translations')) {
} //method } //method
} //class } //class
}
/* /*
$obj = new number_translations; $obj = new number_translations;
$obj->delete(); $obj->delete();
*/ */
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the phrases class //define the phrases class
if (!class_exists('phrases')) {
class phrases { class phrases {
/** /**
@ -431,6 +430,3 @@ if (!class_exists('phrases')) {
} //method } //method
} //class } //class
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the pin numbers class //define the pin numbers class
if (!class_exists('pin_numbers')) {
class pin_numbers { class pin_numbers {
/** /**
@ -245,6 +244,3 @@ if (!class_exists('pin_numbers')) {
} }
} }
}
?>

View File

@ -26,7 +26,6 @@
*/ */
//define the switch_recordings class //define the switch_recordings class
if (!class_exists('switch_recordings')) {
class switch_recordings { class switch_recordings {
/** /**
@ -158,6 +157,3 @@ if (!class_exists('switch_recordings')) {
} //method } //method
} //class } //class
}
?>

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -88,7 +88,6 @@
$registrations = $obj->get($profile ?? null); $registrations = $obj->get($profile ?? null);
//order the array //order the array
require_once "resources/classes/array_order.php";
$order = new array_order(); $order = new array_order();
$registrations = $order->sort($registrations, 'sip-auth-realm', 'user'); $registrations = $order->sort($registrations, 'sip-auth-realm', 'user');

View File

@ -25,7 +25,6 @@
*/ */
//define the ring groups class //define the ring groups class
if (!class_exists('ring_groups')) {
class ring_groups { class ring_groups {
/** /**
@ -512,6 +511,3 @@ if (!class_exists('ring_groups')) {
} }
} }
}
?>

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -25,7 +25,6 @@
*/ */
//define the sip profiles class //define the sip profiles class
if (!class_exists('sip_profiles')) {
class sip_profiles { class sip_profiles {
/** /**
@ -434,6 +433,3 @@ if (!class_exists('sip_profiles')) {
} }
} }
}
?>

View File

@ -26,12 +26,7 @@
/** /**
* sofia_global_settings class * sofia_global_settings class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('sofia_global_settings')) {
class sofia_global_settings { class sofia_global_settings {
/** /**
@ -247,6 +242,3 @@ if (!class_exists('sofia_global_settings')) {
} }
} }
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the streams class //define the streams class
if (!class_exists('streams')) {
class streams { class streams {
/** /**
@ -244,6 +243,3 @@ if (!class_exists('streams')) {
} }
} }
}
?>

View File

@ -23,12 +23,7 @@
/** /**
* presence class * presence class
*
* @method boolean active
* @method array show
*/ */
if (!class_exists('presence')) {
class presence { class presence {
/** /**
@ -84,7 +79,6 @@ if (!class_exists('presence')) {
return $array; return $array;
} }
} }
}
//examples //examples
/* /*
@ -97,11 +91,9 @@ if (!class_exists('presence')) {
echo "active: true\n"; echo "active: true\n";
} }
else { else {
echo "active: false\n"; echo "active: false\n";
} }
//show active the presence //show active the presence
$presence = new presence; $presence = new presence;
$array = $presence->show(); $array = $presence->show();
*/ */
?>

View File

@ -25,7 +25,6 @@
Matthew Vale <github@mafoo.org> Matthew Vale <github@mafoo.org>
*/ */
if (!class_exists('ringbacks')) {
class ringbacks { class ringbacks {
//define variables //define variables
@ -85,18 +84,15 @@ if (!class_exists('ringbacks')) {
*/ */
//get the tones //get the tones
require_once "resources/classes/tones.php";
$tones = new tones; $tones = new tones;
$this->tones_list = $tones->tones_list(); $this->tones_list = $tones->tones_list();
//get music on hold and recordings //get music on hold and recordings
if (is_dir($_SERVER["PROJECT_ROOT"].'/app/music_on_hold')) { if (is_dir($_SERVER["PROJECT_ROOT"].'/app/music_on_hold')) {
require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
$music = new switch_music_on_hold; $music = new switch_music_on_hold;
$this->music_list = $music->get(); $this->music_list = $music->get();
} }
if (is_dir($_SERVER["PROJECT_ROOT"].'/app/recordings')) { if (is_dir($_SERVER["PROJECT_ROOT"].'/app/recordings')) {
require_once "app/recordings/resources/classes/switch_recordings.php";
$recordings = new switch_recordings; $recordings = new switch_recordings;
$this->recordings_list = $recordings->list_recordings(); $this->recordings_list = $recordings->list_recordings();
} }
@ -232,6 +228,3 @@ if (!class_exists('ringbacks')) {
return $select; return $select;
} }
} }
}
?>

View File

@ -26,12 +26,7 @@
/** /**
* switch class provides methods for copying switch_files * switch class provides methods for copying switch_files
*
* @method string correct_path
* @method string copy_scripts
* @method string copy_languages
*/ */
if (!class_exists('switch_files')) {
class switch_files { class switch_files {
/** /**
@ -158,7 +153,6 @@ if (!class_exists('switch_files')) {
} }
} }
}
/* /*
//example use //example use
@ -168,5 +162,3 @@ if (!class_exists('switch_files')) {
$obj->copy_scripts(); $obj->copy_scripts();
$obj->copy_languages(); $obj->copy_languages();
*/ */
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the time conditions class //define the time conditions class
if (!class_exists('time_conditions')) {
class time_conditions { class time_conditions {
/** /**
@ -346,6 +345,3 @@
} //class } //class
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the vars class //define the vars class
if (!class_exists('vars')) {
class vars { class vars {
/** /**
@ -258,6 +257,3 @@ if (!class_exists('vars')) {
} }
} }
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the voicemail greetings class //define the voicemail greetings class
if (!class_exists('voicemail_greetings')) {
class voicemail_greetings { class voicemail_greetings {
/** /**
@ -166,6 +165,3 @@ if (!class_exists('voicemail_greetings')) {
} //method } //method
} //class } //class
}
?>

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -1581,7 +1581,6 @@
} }
//example voicemail messages //example voicemail messages
//require_once "app/voicemails/resources/classes/voicemail.php";
//$voicemail = new voicemail; //$voicemail = new voicemail;
//$voicemail->voicemail_uuid = $voicemail_uuid; //$voicemail->voicemail_uuid = $voicemail_uuid;
//$voicemail->order_by = $order_by; //$voicemail->order_by = $order_by;

View File

@ -23,9 +23,6 @@
//voicemail //voicemail
echo "<div class='hud_box'>\n"; echo "<div class='hud_box'>\n";
//required class
require_once "app/voicemails/resources/classes/voicemail.php";
//get the voicemail //get the voicemail
$vm = new voicemail; $vm = new voicemail;
$vm->domain_uuid = $_SESSION['domain_uuid']; $vm->domain_uuid = $_SESSION['domain_uuid'];

View File

@ -47,7 +47,6 @@
//toggle the voicemail message //toggle the voicemail message
$toggled = 0; $toggled = 0;
if (is_array($voicemail_messages) && sizeof($voicemail_messages) > 0) { if (is_array($voicemail_messages) && sizeof($voicemail_messages) > 0) {
require_once "resources/classes/voicemail.php";
foreach ($voicemail_messages as $voicemail_uuid => $voicemail_message_uuids) { foreach ($voicemail_messages as $voicemail_uuid => $voicemail_message_uuids) {
foreach ($voicemail_message_uuids as $voicemail_message_uuid) { foreach ($voicemail_message_uuids as $voicemail_message_uuid) {
if (is_uuid($voicemail_uuid) && is_uuid($voicemail_message_uuid)) { if (is_uuid($voicemail_uuid) && is_uuid($voicemail_message_uuid)) {

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -26,10 +26,7 @@
/** /**
* xml_cdr class provides methods for adding cdr records to the database * xml_cdr class provides methods for adding cdr records to the database
*
* @method boolean add
*/ */
if (!class_exists('xml_cdr')) {
class xml_cdr { class xml_cdr {
/** /**
@ -2370,4 +2367,3 @@ if (!class_exists('xml_cdr')) {
} }
} //class } //class
}

View File

@ -27,7 +27,6 @@
//includes files //includes files
require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php"; require_once "resources/check_auth.php";
require_once "resources/classes/waveform.php";
use maximal\audio\Waveform; use maximal\audio\Waveform;

View File

@ -96,7 +96,6 @@ class authentication {
//process the plugin //process the plugin
if (file_exists($plugin)) { if (file_exists($plugin)) {
//run the plugin //run the plugin
include_once $plugin;
$object = new $class_name(); $object = new $class_name();
$object->domain_name = $this->domain_name; $object->domain_name = $this->domain_name;
$object->domain_uuid = $this->domain_uuid; $object->domain_uuid = $this->domain_uuid;

View File

@ -26,8 +26,6 @@
/** /**
* plugin_email * plugin_email
*
* @method email time based one time password authenticate the user
*/ */
class plugin_email { class plugin_email {
@ -521,5 +519,3 @@ class plugin_email {
} }
} }
?>

View File

@ -209,5 +209,3 @@ class plugin_ldap {
return $result; return $result;
} }
} }
?>

View File

@ -439,5 +439,3 @@ class plugin_totp {
} }
} }
?>

View File

@ -42,7 +42,6 @@ if (!empty($_GET)) {
$text = $language->get(); $text = $language->get();
//create the vcard object //create the vcard object
require_once "resources/classes/vcard.php";
$vcard = new vcard(); $vcard = new vcard();
//get the contact id //get the contact id

View File

@ -25,7 +25,6 @@
*/ */
//define the contacts class //define the contacts class
if (!class_exists('contacts')) {
class contacts { class contacts {
const APP_NAME = "contacts"; const APP_NAME = "contacts";
@ -277,6 +276,3 @@ if (!class_exists('contacts')) {
} //method } //method
} //class } //class
}
?>

View File

@ -26,12 +26,7 @@
/** /**
* dashboard class * dashboard class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('dashboard')) {
class dashboard { class dashboard {
/** /**
@ -247,6 +242,3 @@ if (!class_exists('dashboard')) {
} }
} }
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the databases class //define the databases class
if (!class_exists('databases')) {
class databases { class databases {
/** /**
@ -169,6 +168,3 @@ if (!class_exists('databases')) {
} }
} }
}
?>

View File

@ -26,12 +26,7 @@
/** /**
* default_settings class * default_settings class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('default_settings')) {
class default_settings { class default_settings {
/** /**
@ -327,6 +322,3 @@ if (!class_exists('default_settings')) {
} //method } //method
} //class } //class
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the domain settings class //define the domain settings class
if (!class_exists('domain_settings')) {
class domain_settings { class domain_settings {
/** /**
@ -386,6 +385,3 @@ if (!class_exists('domain_settings')) {
} //method } //method
} //class } //class
}
?>

View File

@ -486,7 +486,6 @@
//recreate dialplan and extension xml files //recreate dialplan and extension xml files
if (is_readable($_SESSION['switch']['extensions']['dir'])) { if (is_readable($_SESSION['switch']['extensions']['dir'])) {
require_once $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/extensions/resources/classes/extension.php";
$extension = new extension; $extension = new extension;
$extension->xml(); $extension->xml();
} }

View File

@ -25,7 +25,6 @@
*/ */
//define the email templates class //define the email templates class
if (!class_exists('email_templates')) {
class email_templates { class email_templates {
/** /**
@ -244,6 +243,3 @@ if (!class_exists('email_templates')) {
} }
} }
}
?>

View File

@ -2,9 +2,6 @@
/** /**
* events class provides an event system * events class provides an event system
*
* @method void load_plugins
* @method dynamic __call
*/ */
class events { class events {
@ -31,11 +28,7 @@ class events {
//create the database connection //create the database connection
//includes files //includes files
require_once dirname(__DIR__, 4) . "/resources/require.php"; $database = database::new();
//includes files
require_once "resources/classes/database.php";
$database = new database;
$database->connect(); $database->connect();
$this->db = $database->db; $this->db = $database->db;
return $this->db = $database->db; return $this->db = $database->db;

View File

@ -43,7 +43,6 @@
$text = $language->get(); $text = $language->get();
//permission restore default //permission restore default
require_once "core/groups/resources/classes/permission.php";
$permission = new permission; $permission = new permission;
$permission->restore(); $permission->restore();

View File

@ -1,6 +1,5 @@
<?php <?php
if (!class_exists('install')) {
class install { class install {
/** /**
@ -154,7 +153,7 @@ if (!class_exists('install')) {
if(!$file_handle) { return; } if(!$file_handle) { return; }
fwrite($file_handle, $conf); fwrite($file_handle, $conf);
fclose($file_handle); fclose($file_handle);
//if the config.conf file was saved return true //if the config.conf file was saved return true
if (file_exists($config_file)) { if (file_exists($config_file)) {
return true; return true;
@ -166,6 +165,3 @@ if (!class_exists('install')) {
} }
} }
}
?>

View File

@ -51,7 +51,6 @@
} }
//menu restore default //menu restore default
//require_once "resources/classes/menu.php";
$menu = new menu; $menu = new menu;
$menu->menu_uuid = $menu_uuid; $menu->menu_uuid = $menu_uuid;
$menu->menu_language = $menu_language; $menu->menu_language = $menu_language;

View File

@ -2,10 +2,7 @@
/** /**
* software class * software class
*
* @method string version
*/ */
if (!class_exists('software')) {
class software { class software {
/** /**
@ -25,6 +22,3 @@ if (!class_exists('software')) {
} }
} }
}
?>

View File

@ -133,7 +133,6 @@
//load an array of the database schema and compare it with the active database //load an array of the database schema and compare it with the active database
if (!empty($action["upgrade_schema"]) && permission_exists("upgrade_schema")) { if (!empty($action["upgrade_schema"]) && permission_exists("upgrade_schema")) {
require_once "resources/classes/schema.php";
$obj = new schema(); $obj = new schema();
if (isset($action["data_types"]) && $action["data_types"] == 'true') { if (isset($action["data_types"]) && $action["data_types"] == 'true') {
$obj->data_types = true; $obj->data_types = true;

View File

@ -189,8 +189,6 @@
//run all app_defaults.php files //run all app_defaults.php files
if ($upgrade_type == 'domains') { if ($upgrade_type == 'domains') {
require_once "resources/classes/config.php";
require_once "resources/classes/domains.php";
$domain = new domains; $domain = new domains;
$domain->display_type = $display_type; $domain->display_type = $display_type;
$domain->upgrade(); $domain->upgrade();
@ -199,7 +197,6 @@
//upgrade schema and/or data_types //upgrade schema and/or data_types
if ($upgrade_type == 'schema') { if ($upgrade_type == 'schema') {
//get the database schema put it into an array then compare and update the database as needed. //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; $obj = new schema;
if (isset($argv[2]) && $argv[2] == 'data_types') { if (isset($argv[2]) && $argv[2] == 'data_types') {
$obj->data_types = true; $obj->data_types = true;

View File

@ -46,8 +46,6 @@
} }
//run all app_defaults.php files //run all app_defaults.php files
require_once "resources/classes/config.php";
require_once "resources/classes/domains.php";
$domain = new domains; $domain = new domains;
$domain->display_type = $display_type; $domain->display_type = $display_type;
$domain->upgrade(); $domain->upgrade();

View File

@ -273,8 +273,6 @@ function do_upgrade_code_submodules() {
* Execute all app_defaults.php files * Execute all app_defaults.php files
*/ */
function do_upgrade_domains() { 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 = new domains;
$domain->display_type = 'text'; $domain->display_type = 'text';
$domain->upgrade(); $domain->upgrade();
@ -285,7 +283,6 @@ function do_upgrade_domains() {
*/ */
function do_upgrade_schema(bool $data_types = false) { 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. //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 = new schema;
$obj->data_types = $data_types; $obj->data_types = $data_types;
echo $obj->schema('text'); echo $obj->schema('text');

View File

@ -59,7 +59,6 @@
$text = $language->get(); $text = $language->get();
//get the database schema put it into an array then compare and update the database as needed. //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; $obj = new schema;
if (isset($argv[1]) && $argv[1] == 'data_types') { if (isset($argv[1]) && $argv[1] == 'data_types') {
$obj->data_types = true; $obj->data_types = true;

View File

@ -26,12 +26,7 @@
/** /**
* user_logs class * user_logs class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('user_logs')) {
class user_logs { class user_logs {
/** /**
@ -151,6 +146,3 @@ if (!class_exists('user_logs')) {
} }
} }
}
?>

View File

@ -25,7 +25,6 @@
*/ */
//define the user settings class //define the user settings class
if (!class_exists('user_settings')) {
class user_settings { class user_settings {
/** /**
@ -181,6 +180,3 @@ if (!class_exists('user_settings')) {
} //method } //method
} //class } //class
}
?>

View File

@ -107,7 +107,6 @@ Mark J Crane <markjcrane@fusionpbx.com>
//revoke temporary permissions //revoke temporary permissions
$p->delete('user_setting_delete', 'temp'); $p->delete('user_setting_delete', 'temp');
//reset session variables to default //reset session variables to default
require "resources/classes/domains.php";
$domain = new domains(); $domain = new domains();
$domain->set(); $domain->set();
} }

View File

@ -26,12 +26,7 @@
/** /**
* users class * users class
*
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('users')) {
class users { class users {
/** /**
@ -315,6 +310,3 @@ if (!class_exists('users')) {
} }
} }
} }
}
?>

View File

@ -1,29 +1,37 @@
<?php <?php
/* /*
FusionPBX FusionPBX
Version: MPL 1.1 Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with 1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/ http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis, Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the for the specific language governing rights and limitations under the
License. License.
The Original Code is FusionPBX The Original Code is FusionPBX
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2024 Portions created by the Initial Developer are Copyright (C) 2008-2024
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
*/ */
/**
* Auto Loader class
* Searches for project files when a class is required. Debugging mode can be set using:
* - export DEBUG=1
* OR
* - debug=true is appended to the url
*/
class auto_loader { class auto_loader {
const FILE = 'autoloader_cache.php'; const FILE = 'autoloader_cache.php';
@ -37,11 +45,20 @@ class auto_loader {
*/ */
private $apcu_enabled; private $apcu_enabled;
/**
* Cache path and file name
* @var string
*/
private static $cache_file = null;
public function __construct($project_path = '') { public function __construct($project_path = '') {
//set if we can use RAM cache //set if we can use RAM cache
$this->apcu_enabled = function_exists('apcu_enabled') && apcu_enabled(); $this->apcu_enabled = function_exists('apcu_enabled') && apcu_enabled();
//set cache location
self::$cache_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . self::FILE;
//classes must be loaded before this object is registered //classes must be loaded before this object is registered
if (!$this->load_cache()) { if (!$this->load_cache()) {
//cache miss so load them //cache miss so load them
@ -61,12 +78,14 @@ class auto_loader {
//update RAM cache when available //update RAM cache when available
if ($this->apcu_enabled) { if ($this->apcu_enabled) {
apcu_store(self::CACHE_KEY, $this->classes); $success = apcu_store(self::CACHE_KEY, $this->classes);
//do not save to drive when we are using apcu
if ($success) return true;
} }
//ensure we have somewhere to put the file //ensure we have somewhere to put the file
if (empty($file)) { if (empty($file)) {
$file = sys_get_temp_dir() . '/' . self::FILE; $file = self::$cache_file;
} }
//export the classes array using PHP engine //export the classes array using PHP engine
@ -77,13 +96,10 @@ class auto_loader {
if ($result !== false) { if ($result !== false) {
return true; return true;
} }
//file failed to save - send error to syslog when debugging
$error_array = error_get_last(); $error_array = error_get_last();
//send to syslog when debugging self::log(LOG_WARNING, $error_array['message'] ?? '');
if (!empty($_REQUEST['debug']) && $_REQUEST['debug'] == 'true') {
openlog("PHP", LOG_PID | LOG_PERROR, LOG_LOCAL0);
syslog(LOG_WARNING, "[php][auto_loader] " . $error_array['message']);
closelog();
}
return false; return false;
} }
@ -99,21 +115,21 @@ class auto_loader {
//use a standard file //use a standard file
if (empty($file)) { if (empty($file)) {
$file = sys_get_temp_dir() . '/'. self::FILE; $file = self::$cache_file;
} }
//use PHP engine to parse it //use PHP engine to parse it
if (file_exists($file)) { if (file_exists($file)) {
$this->classes = include $file; $this->classes = include $file;
} }
//assign to an array
if (!empty($this->classes)) { //catch edge case of first time using apcu cache
//cache edge case of first time using apcu cache if ($this->apcu_enabled) {
if ($this->apcu_enabled) { apcu_store(self::CACHE_KEY, $this->classes);
apcu_store(self::CACHE_KEY, $this->classes);
}
return true;
} }
return false;
//return true when we have classes and false if the array is still empty
return !empty($this->classes);
} }
public function reload_classes($project_path = '') { public function reload_classes($project_path = '') {
@ -122,26 +138,87 @@ class auto_loader {
$project_path = dirname(__DIR__, 2); $project_path = dirname(__DIR__, 2);
} }
//build the array of all classes //build the array of all locations for classes in specific order
$search_path = []; $search_path = [
$search_path = array_merge($search_path, glob($project_path . '/resources/classes/*.php')); $project_path . '/resources/interfaces/*.php',
$search_path = array_merge($search_path, glob($project_path . '/resources/interfaces/*.php')); $project_path . '/resources/traits/*.php',
$search_path = array_merge($search_path, glob($project_path . '/resources/traits/*.php')); $project_path . '/resources/classes/*.php',
$search_path = array_merge($search_path, glob($project_path . '/*/*/resources/classes/*.php')); $project_path . '/*/*/resources/interfaces/*.php',
$search_path = array_merge($search_path, glob($project_path . '/*/*/resources/interfaces/*.php')); $project_path . '/*/*/resources/traits/*.php',
$search_path = array_merge($search_path, glob($project_path . '/*/*/resources/traits/*.php')); $project_path . '/*/*/resources/classes/*.php',
$project_path . '/core/authentication/resources/classes/plugins/*.php',
];
//get all php files for each path
$files = [];
foreach ($search_path as $path) {
$files = array_merge($files, glob($path));
}
//reset the current array //reset the current array
$this->classes = []; $this->classes = [];
//store the class name (key) and the path (value) //store PHP language declared classes, interfaces, and traits
foreach ($search_path as $path) { $curr_classes = get_declared_classes();
$this->classes[basename($path, '.php')] = $path; $curr_interfaces = get_declared_interfaces();
} $curr_traits = get_declared_traits();
//store the class name (key) and the path (value)
foreach ($files as $file) {
//include the new class
try {
include_once $file;
} catch (Exception $e) {
//report the error
self::log(LOG_ERR, "Exception while trying to include file '$file': " . $e->getMessage());
continue;
}
//get the new classes
$new_classes = get_declared_classes();
$new_interfaces = get_declared_interfaces();
$new_traits = get_declared_traits();
//check for a new class
$classes = array_diff($new_classes, $curr_classes);
if (!empty($classes)) {
foreach ($classes as $class) {
$this->classes[$class] = $file;
}
//overwrite previous array with new values
$curr_classes = $new_classes;
}
//check for a new interface
$interfaces = array_diff($new_interfaces, $curr_interfaces);
if (!empty($interfaces)) {
foreach ($interfaces as $interface) {
$this->classes[$interface] = $file;
}
//overwrite previous array with new values
$curr_interfaces = $new_interfaces;
}
//check for a new trait
$traits = array_diff($new_traits, $curr_traits);
if (!empty($traits)) {
foreach ($traits as $trait) {
$this->classes[$trait] = $file;
}
//overwrite previous array with new values
$curr_traits = $new_traits;
}
}
} }
private function loader($class_name) : bool { /**
* The loader is set to private because only the PHP engine should be calling this method
* @param string $class_name The class name that needs to be loaded
* @return bool True if the class is loaded or false when the class is not found
* @access private
*/
private function loader($class_name): bool {
//sanitize the class name //sanitize the class name
$class_name = preg_replace('[^a-zA-Z0-9_]', '', $class_name); $class_name = preg_replace('[^a-zA-Z0-9_]', '', $class_name);
@ -161,32 +238,29 @@ class auto_loader {
} }
//cache miss //cache miss
if (!empty($_REQUEST['debug']) && $_REQUEST['debug'] == 'true') { self::log(LOG_WARNING, "class '$class_name' not found in cache");
openlog("PHP", LOG_PID | LOG_PERROR, LOG_LOCAL0);
syslog(LOG_WARNING, "[php][auto_loader] class not found in cache: ".$class_name);
closelog();
}
//set project path using magic dir constant //set project path using magic dir constant
$project_path = dirname(__DIR__, 2); $project_path = dirname(__DIR__, 2);
//build the search path array //build the search path array
$search_path[] = glob($project_path . "/resources/classes/".$class_name.".php"); $search_path[] = glob($project_path . "/resources/interfaces/" . $class_name . ".php");
$search_path[] = glob($project_path . "/resources/interfaces/".$class_name.".php"); $search_path[] = glob($project_path . "/resources/traits/" . $class_name . ".php");
$search_path[] = glob($project_path . "/resources/traits/".$class_name.".php"); $search_path[] = glob($project_path . "/resources/classes/" . $class_name . ".php");
$search_path[] = glob($project_path . "/*/*/resources/classes/".$class_name.".php"); $search_path[] = glob($project_path . "/*/*/resources/interfaces/" . $class_name . ".php");
$search_path[] = glob($project_path . "/*/*/resources/interfaces/".$class_name.".php"); $search_path[] = glob($project_path . "/*/*/resources/traits/" . $class_name . ".php");
$search_path[] = glob($project_path . "/*/*/resources/traits/".$class_name.".php"); $search_path[] = glob($project_path . "/*/*/resources/classes/" . $class_name . ".php");
//find the path //collapse all entries to only the matched entry
$path = self::autoload_search($search_path); $matches = array_filter($search_path);
if (!empty($path)) { if (!empty($matches)) {
$path = array_pop($matches)[0];
//include the class or interface //include the class, interface, or trait
include $path; include_once $path;
//make sure to reload the cache after we found a new class //inject the class in to the array
$this->reload_classes(); $this->classes[$class_name] = $path;
//update the cache with new classes //update the cache with new classes
$this->update_cache(); $this->update_cache();
@ -196,35 +270,54 @@ class auto_loader {
} }
//send to syslog when debugging //send to syslog when debugging
if (!empty($_REQUEST['debug']) && $_REQUEST['debug'] == 'true') { self::log(LOG_ERR, "class '$class_name' not found name");
openlog("PHP", LOG_PID | LOG_PERROR, LOG_LOCAL0);
syslog(LOG_WARNING, "[php][auto_loader] class not found name: ".$class_name);
closelog();
}
//return boolean //return boolean
return false; return false;
} }
public static function autoload_search($array) : string { /**
foreach($array as $path) { * Returns a list of classes loaded by the auto_loader. If no classes have been loaded an empty array is returned.
if (is_array($path) && count($path) != 0) { * @return array List of classes loaded by the auto_loader or empty array
foreach($path as $sub_path) { */
if (!empty($sub_path) && file_exists($sub_path)) { public function get_class_list(): array {
return $sub_path; if (!empty($this->classes)) {
} return $this->classes;
}
}
elseif (!empty($path) && file_exists($path)) {
return $path;
}
} }
return ''; return [];
} }
public static function clear_cache() { public static function clear_cache(string $file = '') {
//check for apcu cache
if (function_exists('apcu_enabled') && apcu_enabled()) { if (function_exists('apcu_enabled') && apcu_enabled()) {
apcu_delete(self::CACHE_KEY); apcu_delete(self::CACHE_KEY);
} }
//set default file
if (empty(self::$cache_file)) {
self::$cache_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . self::FILE;
}
//set file to clear
if (empty($file)) {
$file = self::$cache_file;
}
//remove the file when it exists
if (file_exists($file)) {
@unlink($file);
$error_array = error_get_last();
//send to syslog when debugging with either environment variable or debug in the url
self::log(LOG_WARNING, $error_array['message'] ?? '');
}
}
private static function log(int $level, string $message): void {
if (filter_var($_REQUEST['debug'] ?? false, FILTER_VALIDATE_BOOL) || filter_var(getenv('DEBUG') ?? false, FILTER_VALIDATE_BOOL)) {
openlog("PHP", LOG_PID | LOG_PERROR, LOG_LOCAL0);
syslog($level, "[auto_loader] " . $message);
closelog();
}
} }
} }

View File

@ -25,7 +25,6 @@
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
*/ */
if (!class_exists('button')) {
class button { class button {
public static $collapse = 'hide-md-dn'; public static $collapse = 'hide-md-dn';
@ -127,7 +126,6 @@ if (!class_exists('button')) {
$button = $anchor.$button."</a>"; $button = $anchor.$button."</a>";
} }
return $button; return $button;
unset($button);
} }
private static function quote($value) { private static function quote($value) {
@ -135,7 +133,6 @@ if (!class_exists('button')) {
} }
} }
}
/* /*
@ -236,5 +233,3 @@ if (!class_exists('button')) {
*/ */
?>

View File

@ -3279,7 +3279,7 @@
* @see database::__construct() * @see database::__construct()
* @see database::connect() * @see database::connect()
*/ */
public static function new(array $params = []) { public static function new(array $params = []): static {
if (self::$database === null) { if (self::$database === null) {
self::$database = new database($params); self::$database = new database($params);
if (!self::$database->is_connected()) { if (!self::$database->is_connected()) {
@ -3326,7 +3326,6 @@
/* /*
//example usage //example usage
//find //find
require_once "resources/classes/database.php";
$database = new database; $database = new database;
$database->domain_uuid = $_SESSION["domain_uuid"]; $database->domain_uuid = $_SESSION["domain_uuid"];
$database->type = $db_type; $database->type = $db_type;
@ -3343,7 +3342,6 @@
$database->find(); $database->find();
print_r($database->result); print_r($database->result);
//insert //insert
require_once "resources/classes/database.php";
$database = new database; $database = new database;
$database->domain_uuid = $_SESSION["domain_uuid"]; $database->domain_uuid = $_SESSION["domain_uuid"];
$database->table = "v_ivr_menus"; $database->table = "v_ivr_menus";

View File

@ -28,11 +28,7 @@
/** /**
* domains class * domains class
* *
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('domains')) {
class domains { class domains {
/** /**
@ -786,6 +782,3 @@ if (!class_exists('domains')) {
} }
} }
}
?>

View File

@ -27,9 +27,7 @@
/** /**
* email class * email class
* *
* @method boolean send
*/ */
if (!class_exists('email')) {
class email { class email {
/** /**
@ -625,7 +623,7 @@ if (!class_exists('email')) {
} }
} }
}
/* /*
$email = new email; $email = new email;

View File

@ -27,11 +27,7 @@
/** /**
* groups class provides methods for add, delete groups, and add default groups * groups class provides methods for add, delete groups, and add default groups
* *
* @method null delete
* @method null toggle
* @method null copy
*/ */
if (!class_exists('groups')) {
class groups { class groups {
/** /**
@ -534,6 +530,3 @@ if (!class_exists('groups')) {
$_SESSION["user"]["group_level"] = $this->group_level; $_SESSION["user"]["group_level"] = $this->group_level;
} }
} }
}
?>

Some files were not shown because too many files have changed in this diff Show More