Skip to content

Commit

Permalink
Replace custom loader in favor of composer native
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 7, 2023
1 parent 8f871c7 commit 8103e9d
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 124 deletions.
1 change: 0 additions & 1 deletion .github/workflows/browser_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:

- name: Setup composer
run: |
cp composer.json-dist composer.json
composer require "laravel/dusk:^7.9" --no-update
- name: Install dependencies
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:

- name: Setup composer
run: |
cp composer.json-dist composer.json
composer require "kolab/net_ldap3:~1.1.1" --no-update
- name: Fix PHPUnit for PHP 8.2
Expand Down
3 changes: 1 addition & 2 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ REQUIREMENTS
- LDAP for LDAP addressbook support (optional)
- GD, Imagick, XMLWriter (optional: thumbnails generation, QR-code)
* PEAR and PEAR packages distributed with Roundcube or external.
See composer.json-dist for the list of required packages.
See composer.json for the list of required packages.
* php.ini options:
- memory_limit > 16MB
- file_uploads enabled (for uploading attachments and import files)
Expand All @@ -40,7 +40,6 @@ INSTALLATION
you have to install PHP and javascript dependencies.
2.1. Install PHP dependencies using composer:
- get composer from https://getcomposer.org/download/
- rename the composer.json-dist file into composer.json
- if you want to use LDAP address books, enable the LDAP libraries in your
composer.json file by moving the items from "suggest" to the "require"
section (remove the explanation texts after the version!).
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ all: clean complete dependent framework

complete: roundcubemail-git
cp -RH roundcubemail-git roundcubemail-$(VERSION)
(cd roundcubemail-$(VERSION); cp composer.json-dist composer.json)
(cd roundcubemail-$(VERSION); php /tmp/composer.phar config platform.php $(PHP_VERSION))
(cd roundcubemail-$(VERSION); php /tmp/composer.phar require "kolab/net_ldap3:~1.1.1" --no-update --no-install)
(cd roundcubemail-$(VERSION); php /tmp/composer.phar config --unset suggest.kolab/net_ldap3)
Expand Down
1 change: 0 additions & 1 deletion UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ it on a unix system, you need to do the following operations by hand:
by running `php composer.phar update --no-dev`.
4b. Install/update dependencies using composer:
- get composer from https://getcomposer.org/download/
- rename the composer.json-dist file into composer.json
- if you want to use LDAP address books, enable the LDAP libraries in your
composer.json file by moving the items from "suggest" to the "require"
section (remove the explanation texts after the version!).
Expand Down
2 changes: 1 addition & 1 deletion bin/installto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if (strtolower($input) == 'y') {
}
}

foreach (['index.php','config/defaults.inc.php','composer.json-dist','jsdeps.json','CHANGELOG.md','README.md','UPGRADING','LICENSE','INSTALL'] as $file) {
foreach (['index.php','config/defaults.inc.php','composer.json','jsdeps.json','CHANGELOG.md','README.md','UPGRADING','LICENSE','INSTALL'] as $file) {
$command = "rsync -a --out-format=%n " . INSTALL_PATH . "$file $target_dir/$file";

if (file_exists(INSTALL_PATH . $file) && (system($command, $ret) === false || $ret > 0)) {
Expand Down
12 changes: 12 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
"kolab/net_ldap3": "~1.1.1 required for connecting to LDAP",
"bjeavons/zxcvbn-php": "^1.0 required for Zxcvbn password strength driver"
},
"autoload": {
"classmap": [
"program/actions/",
"program/include/",
"program/lib/"
]
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"config": {
"allow-plugins": {
"roundcube/plugin-installer": true
Expand Down
2 changes: 1 addition & 1 deletion plugins/password/README
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@
-------------

Driver to use the Zxcvbn library to check password strength. Requires zxcvbn-php library.
The library is not distributed with Roundcube (see composer.json-dist).
The library is not distributed with Roundcube (see composer.json).
Note: Required PHP's memory_limit >= 24M.

Set $config['password_zxcvbn_min_score'] to define minimum acceptable password strength score.
Expand Down
37 changes: 1 addition & 36 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) {
die("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 @@ -75,32 +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
Expand Down
2 changes: 1 addition & 1 deletion program/lib/Roundcube/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ INSTALLATION
------------
Copy all files of this directory to your project or install it in the default
include_path directory of your webserver. Some classes of the framework require
external libraries. See composer.json-dist for the list of required packages.
external libraries. See composer.json for the list of required packages.


USAGE
Expand Down
56 changes: 0 additions & 56 deletions program/lib/Roundcube/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,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')) {
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, function($err) { rcube::raise_error($err, true); });
Expand Down Expand Up @@ -409,46 +396,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;
}
else if (strpos($classname, 'html_') === 0 || $classname === 'html') {
$classname = 'Roundcube/html';
}
else if (strpos($classname, 'Mail_') === 0) {
$classname = 'Mail/' . substr($classname, 5);
}
else if (strpos($classname, 'Net_') === 0) {
$classname = 'Net/' . substr($classname, 4);
}
else if (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;
}
10 changes: 0 additions & 10 deletions tests/Browser/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +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
Expand Down
13 changes: 0 additions & 13 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,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) {
die("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();

Expand Down

0 comments on commit 8103e9d

Please sign in to comment.