Skip to content

Commit

Permalink
minor legacy autoload improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 11, 2024
1 parent 800ba62 commit ec51bbb
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions plugins/password/drivers/ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class rcube_ldap_password
public function save($curpass, $passwd)
{
$rcmail = rcmail::get_instance();

require_once 'Net/LDAP2.php';
require_once __DIR__ . '/ldap_simple.php';

Expand Down
2 changes: 1 addition & 1 deletion program/actions/settings/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ public static function timezone_label($tz)
$lang = $_SESSION['language'] ?? 'en_US';
if ($lang && $lang != 'en_US') {
if (file_exists(RCUBE_LOCALIZATION_DIR . "{$lang}/timezones.inc")) {
include RCUBE_LOCALIZATION_DIR . "{$lang}/timezones.inc";
require RCUBE_LOCALIZATION_DIR . "{$lang}/timezones.inc";
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions program/include/iniset.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@
}

// include Roundcube Framework
require_once 'Roundcube/bootstrap.php';
require_once __DIR__ . '/../lib/Roundcube/bootstrap.php';

// register autoloader for rcmail app classes
spl_autoload_register('rcmail_autoload');

/**
* PHP5 autoloader routine for dynamic class loading
*/
function rcmail_autoload($classname)
function rcmail_autoload(string $classname): bool
{
if (strpos($classname, 'rcmail') === 0) {
if (preg_match('/^rcmail_action_([^_]+)_(.*)$/', $classname, $matches)) {
Expand Down
2 changes: 1 addition & 1 deletion program/include/rcmail_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function load_config_file($file)
$config = [];
$rcmail_config = []; // deprecated var name

include $file;
require $file;

// read comments from config file
if (function_exists('token_get_all')) {
Expand Down
10 changes: 2 additions & 8 deletions program/lib/Roundcube/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,9 @@ function version_parse($version)
/**
* Use PHP5 autoload for dynamic class loading
*
* @param string $classname Class name
*
* @return bool True when the class file has been found
*
* @todo Make Zend, PEAR etc play with this
* @todo Make our classes conform to a more straight forward CS.
*/
function rcube_autoload($classname)
function rcube_autoload(string $classname): bool
{
if (strpos($classname, 'rcube') === 0) {
$classname = preg_replace('/^rcube_(cache|db|session|spellchecker)_/', '\1/', $classname);
Expand All @@ -430,8 +425,7 @@ function rcube_autoload($classname)
}

// Translate PHP namespaces into directories,
// i.e. use \Sabre\VObject; $vcf = VObject\Reader::read(...)
// -> Sabre/VObject/Reader.php
// i.e. 'Sabre\Reader' -> 'Sabre/Reader.php'
$classname = str_replace('\\', '/', $classname);

if ($fp = @fopen("{$classname}.php", 'r', true)) {
Expand Down
2 changes: 1 addition & 1 deletion program/lib/Roundcube/rcube.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public static function read_localization_file($file, $texts = [])

// use buffering to handle empty lines/spaces after closing PHP tag
ob_start();
include $file;
require $file;
ob_end_clean();

// @phpstan-ignore-next-line
Expand Down
2 changes: 1 addition & 1 deletion program/lib/Roundcube/rcube_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function load_from_file($file)
if ($fpath && is_file($fpath) && is_readable($fpath)) {
// use output buffering, we don't need any output here
ob_start();
include $fpath;
require $fpath;
ob_end_clean();

if (isset($config) && is_array($config)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Framework/Csv2vcardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function test_localization_files()
{
foreach (glob(RCUBE_LOCALIZATION_DIR . '*/csv2vcard.inc') as $filename) {
$map = null;
include $filename;
require $filename;
$this->assertTrue(count($map) > 0);
}
}
Expand Down

0 comments on commit ec51bbb

Please sign in to comment.