Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native composer autoloader #9241

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions plugins/database_attachments/database_attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

require_once INSTALL_PATH . 'plugins/filesystem_attachments/filesystem_attachments.php';

class database_attachments extends filesystem_attachments
{
// Cache object
Expand Down
2 changes: 0 additions & 2 deletions plugins/debug_logger/debug_logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ class debug_logger extends rcube_plugin

public function init()
{
require_once __DIR__ . '/runlog/runlog.php';

$this->runlog = new runlog();

if (!rcmail::get_instance()->config->get('log_dir')) {
Expand Down
5 changes: 0 additions & 5 deletions plugins/enigma/enigma.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ public function load_env()

$this->env_loaded = true;

// Add include path for Enigma classes and drivers
$include_path = $this->home . '/lib' . \PATH_SEPARATOR;
$include_path .= ini_get('include_path');
set_include_path($include_path);

// load the Enigma plugin configuration
$this->load_config();

Expand Down
2 changes: 0 additions & 2 deletions plugins/example_addressbook/example_addressbook.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

require_once __DIR__ . '/example_addressbook_backend.php';

/**
* Sample plugin to add a new address book
* with just a static list of contacts
Expand Down
2 changes: 0 additions & 2 deletions plugins/identicon/identicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public function contact_photo($args)
}

if ($email) {
require_once __DIR__ . '/identicon_engine.php';

if (!empty($args['attrib']['bg-color'])) {
$bgcolor = $args['attrib']['bg-color'];
} else {
Expand Down
5 changes: 0 additions & 5 deletions plugins/managesieve/managesieve.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,6 @@ public function managesieve_saveraw()
public function get_engine($type = null)
{
if (!$this->engine) {
// Add include path for internal classes
$include_path = $this->home . '/lib' . \PATH_SEPARATOR;
$include_path .= ini_get('include_path');
set_include_path($include_path);

$class_name = 'rcube_sieve_' . ($type ?: 'engine');
$this->engine = new $class_name($this);
}
Expand Down
11 changes: 0 additions & 11 deletions plugins/markasjunk/markasjunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,6 @@ private function _init_driver()
], true, false);
}

include_once $driver;

if (!class_exists($class, false) || !method_exists($class, 'spam') || !method_exists($class, 'ham')) {
rcube::raise_error([
'code' => 600,
'file' => __FILE__,
'line' => __LINE__,
'message' => "markasjunk plugin: Broken driver: {$driver}",
], true, false);
}

// call the relevant function from the driver
$this->driver = new $class();

Expand Down
1 change: 0 additions & 1 deletion plugins/password/drivers/ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function save($curpass, $passwd)
$rcmail = rcmail::get_instance();

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

// Building user DN
if ($userDN = $rcmail->config->get('password_ldap_userDN_mask')) {
Expand Down
2 changes: 0 additions & 2 deletions plugins/password/drivers/ldap_exop.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

require_once __DIR__ . '/ldap_simple.php';

class rcube_ldap_exop_password extends rcube_ldap_simple_password
{
public function save($curpass, $passwd)
Expand Down
2 changes: 0 additions & 2 deletions plugins/password/drivers/ldap_samba_ad.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

require_once __DIR__ . '/ldap_simple.php';

class rcube_ldap_samba_ad_password extends rcube_ldap_simple_password
{
public function save($curpass, $passwd)
Expand Down
10 changes: 0 additions & 10 deletions plugins/password/password.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,6 @@ private function _load_driver($type = 'password')
return false;
}

include_once $file;

if (!class_exists($class, false) || (!method_exists($class, 'save') && !method_exists($class, 'check_strength'))) {
rcube::raise_error([
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
'message' => "Password plugin: Broken driver {$driver}",
], true, false);
return false;
}

$this->drivers[$type] = new $class();
}

Expand Down
2 changes: 0 additions & 2 deletions plugins/redundant_attachments/redundant_attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

require_once RCUBE_PLUGINS_DIR . 'filesystem_attachments/filesystem_attachments.php';

class redundant_attachments extends filesystem_attachments
{
// A prefix for the cache key used in the session and in the key field of the cache table
Expand Down
34 changes: 0 additions & 34 deletions program/include/iniset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -77,30 +67,6 @@
// include Roundcube Framework
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(string $classname): bool
{
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;
}

/**
* Show a generic error message on fatal PHP error
*/
Expand Down
33 changes: 6 additions & 27 deletions program/lib/Roundcube/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,8 @@
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');
// 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')) {
Expand Down Expand Up @@ -405,25 +395,14 @@ function version_parse($version)
}

/**
* Use PHP5 autoload for dynamic class loading
* 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_autoload(string $classname): bool
function rcube_legacy_autoload(string $classname): bool
{
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. 'Sabre\Reader' -> 'Sabre/Reader.php'
$classname = str_replace('\\', '/', $classname);
Expand Down