Skip to content

Commit

Permalink
keep non-composer autoloading relying on include_path set in plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 7, 2024
1 parent e295b27 commit b814691
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions program/lib/Roundcube/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
mb_internal_encoding(RCUBE_CHARSET);
mb_regex_encoding(RCUBE_CHARSET);

// Register legacy autoloader for plugins
spl_autoload_register('rcube_legacy_autoload');

// set PEAR error handling (will also load the PEAR main class)
if (class_exists('PEAR')) {
// @phpstan-ignore-next-line
Expand Down Expand Up @@ -390,3 +393,25 @@ function version_parse($version)
$version
);
}

/**
* Legacy autoloader for plugins not using or not installed using composer.
*
* @param string $classname Class name
*
* @return bool True when the class file has been found
*/
function rcube_legacy_autoload(string $classname): bool
{
// Translate PHP namespaces into directories,
// i.e. 'Sabre\Reader' -> 'Sabre/Reader.php'
$classname = str_replace('\\', '/', $classname);

if ($fp = @fopen("{$classname}.php", 'r', true)) {
fclose($fp);
include_once "{$classname}.php";
return true;
}

return false;
}

0 comments on commit b814691

Please sign in to comment.