From 176b64fcbc4c0ee6158da217935c897bea9702ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 4 Apr 2024 11:18:56 +0200 Subject: [PATCH] Replace custom loader in favor of composer native --- composer.json | 12 +++++++ program/include/iniset.php | 36 +------------------- program/lib/Roundcube/bootstrap.php | 52 ----------------------------- tests/Browser/bootstrap.php | 9 ----- tests/bootstrap.php | 13 -------- 5 files changed, 13 insertions(+), 109 deletions(-) diff --git a/composer.json b/composer.json index 3316f16552b..10f0cd76719 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,18 @@ "url": "https://plugins.roundcube.net" } ], + "autoload": { + "classmap": [ + "program/actions/", + "program/include/", + "program/lib/" + ] + }, + "autoload-dev": { + "classmap": [ + "tests/" + ] + }, "config": { "allow-plugins": { "ergebnis/composer-normalize": true, diff --git a/program/include/iniset.php b/program/include/iniset.php index 24bf88ae8a8..efc91e98779 100644 --- a/program/include/iniset.php +++ b/program/include/iniset.php @@ -45,16 +45,6 @@ // Show basic error message on fatal PHP error register_shutdown_function('rcmail_error_handler'); -// RC include folders MUST be included FIRST to avoid other -// possible not compatible libraries (i.e PEAR) to be included -// instead the ones provided by RC -$include_path = INSTALL_PATH . 'program/lib' . \PATH_SEPARATOR; -$include_path .= ini_get('include_path'); - -if (set_include_path($include_path) === false) { - exit('Fatal error: ini_set/set_include_path does not work.'); -} - // increase maximum execution time for php scripts // (does not work in safe mode) @set_time_limit(120); @@ -75,31 +65,7 @@ } // include Roundcube Framework -require_once '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) -{ - if (strpos($classname, 'rcmail') === 0) { - if (preg_match('/^rcmail_action_([^_]+)_(.*)$/', $classname, $matches)) { - $filepath = INSTALL_PATH . "program/actions/{$matches[1]}/{$matches[2]}.php"; - } else { - $filepath = INSTALL_PATH . "program/include/{$classname}.php"; - } - - if (is_readable($filepath)) { - include_once $filepath; - return true; - } - } - - return false; -} +require_once __DIR__ . '/../lib/Roundcube/bootstrap.php'; /** * Show a generic error message on fatal PHP error diff --git a/program/lib/Roundcube/bootstrap.php b/program/lib/Roundcube/bootstrap.php index d4657924bab..950256f566b 100644 --- a/program/lib/Roundcube/bootstrap.php +++ b/program/lib/Roundcube/bootstrap.php @@ -92,19 +92,6 @@ mb_internal_encoding(RCUBE_CHARSET); mb_regex_encoding(RCUBE_CHARSET); -// make sure the Roundcube lib directory is in the include_path -$rcube_path = realpath(RCUBE_LIB_DIR . '..'); -$sep = \PATH_SEPARATOR; -$regexp = "!(^|{$sep})" . preg_quote($rcube_path, '!') . "({$sep}|\$)!"; -$path = ini_get('include_path'); - -if (!preg_match($regexp, $path)) { - set_include_path($path . \PATH_SEPARATOR . $rcube_path); -} - -// Register autoloader -spl_autoload_register('rcube_autoload'); - // set PEAR error handling (will also load the PEAR main class) if (class_exists('PEAR')) { // @phpstan-ignore-next-line @@ -403,42 +390,3 @@ function version_parse($version) $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) -{ - if (strpos($classname, 'rcube') === 0) { - $classname = preg_replace('/^rcube_(cache|db|session|spellchecker)_/', '\1/', $classname); - $classname = 'Roundcube/' . $classname; - } elseif (strpos($classname, 'html_') === 0 || $classname === 'html') { - $classname = 'Roundcube/html'; - } elseif (strpos($classname, 'Mail_') === 0) { - $classname = 'Mail/' . substr($classname, 5); - } elseif (strpos($classname, 'Net_') === 0) { - $classname = 'Net/' . substr($classname, 4); - } elseif (strpos($classname, 'Auth_') === 0) { - $classname = 'Auth/' . substr($classname, 5); - } - - // Translate PHP namespaces into directories, - // i.e. use \Sabre\VObject; $vcf = VObject\Reader::read(...) - // -> Sabre/VObject/Reader.php - $classname = str_replace('\\', '/', $classname); - - if ($fp = @fopen("{$classname}.php", 'r', true)) { - fclose($fp); - include_once "{$classname}.php"; - return true; - } - - return false; -} diff --git a/tests/Browser/bootstrap.php b/tests/Browser/bootstrap.php index 50f2ec9b757..d02feb28132 100644 --- a/tests/Browser/bootstrap.php +++ b/tests/Browser/bootstrap.php @@ -34,15 +34,6 @@ define('TESTS_USER', $rcmail->config->get('tests_username')); define('TESTS_PASS', $rcmail->config->get('tests_password')); -require_once __DIR__ . '/Browser.php'; -require_once __DIR__ . '/TestCase.php'; -require_once __DIR__ . '/Components/App.php'; -require_once __DIR__ . '/Components/Dialog.php'; -require_once __DIR__ . '/Components/HtmlEditor.php'; -require_once __DIR__ . '/Components/Popupmenu.php'; -require_once __DIR__ . '/Components/RecipientInput.php'; -require_once __DIR__ . '/Components/Taskmenu.php'; -require_once __DIR__ . '/Components/Toolbarmenu.php'; /** * Utilities for test environment setup diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9503fb158b3..4101641124e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -48,19 +48,6 @@ rcmail::get_instance(0, 'test')->config->set('devel_mode', false); -// Extend include path so some plugin test won't fail -$include_path = ini_get('include_path') . \PATH_SEPARATOR . TESTS_DIR . '..'; -if (set_include_path($include_path) === false) { - exit('Fatal error: ini_set/set_include_path does not work.'); -} - -require_once TESTS_DIR . 'ActionTestCase.php'; -require_once TESTS_DIR . 'ExitException.php'; -require_once TESTS_DIR . 'OutputHtmlMock.php'; -require_once TESTS_DIR . 'OutputJsonMock.php'; -require_once TESTS_DIR . 'StderrMock.php'; -require_once TESTS_DIR . 'StorageMock.php'; - // Initialize database and environment ActionTestCase::init();