Skip to content
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
81 changes: 81 additions & 0 deletions htdocs/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "impresscms/impresscms",
"description": "ImpressCMS - A dynamic and user-friendly Content Management System",
"type": "project",
"keywords": ["cms", "content-management", "php", "mysql", "web"],
"homepage": "https://www.impresscms.org/",
"license": "GPL-2.0",
"authors": [
{
"name": "The ImpressCMS Project",
"homepage": "https://www.impresscms.org/",
"role": "Developer"
}
],
"require": {
"php": ">=7.4.0",
"ext-gd": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-mysqli": "*",
"ext-pcre": "*",
"ext-pdo": "*",
"ext-session": "*",
"ext-xml": "*",
"ext-zlib": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
"Icms\\": "libraries/icms/"
},
"psr-0": {
"icms_": "libraries/"
},
"classmap": [
"libraries/icms.php"
]
},
"autoload-dev": {
"psr-4": {
"Icms\\Tests\\": "../tests/"
}
},
"config": {
"optimize-autoloader": true,
"classmap-authoritative": false,
"apcu-autoloader": true,
"sort-packages": true,
"allow-plugins": {
"*": false
},
"cache-dir": "var/cache/composer",
"vendor-dir": "vendor"
},
"scripts": {
"test": "phpunit",
"cs-check": "phpcs --standard=PSR12 libraries/icms/",
"cs-fix": "phpcbf --standard=PSR12 libraries/icms/",
"optimize-production": [
"composer dump-autoload --optimize --classmap-authoritative --apcu",
"@php -r \"echo 'Production autoloader optimized for ImpressCMS\\n';\""
],
"optimize-development": [
"composer dump-autoload --optimize",
"@php -r \"echo 'Development autoloader optimized for ImpressCMS\\n';\""
],
"post-autoload-dump": [
"@php -r \"echo 'Autoloader optimized for ImpressCMS\\n';\""
]
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x"
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
28 changes: 18 additions & 10 deletions htdocs/include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1612,17 +1612,25 @@ function &icms_getModuleHandler($name = null, $module_dir = null, $module_basena
if (class_exists($class)) {
$handlers[$module_dir][$name] = new $class(icms::$xoopsDB);
} else {
if($module_dir !== 'system') {
if (!file_exists($hnd_file = ICMS_ROOT_PATH . "/modules/{$module_dir}/class/". ucfirst(strtolower($name)) ."Handler.php")) {
$hnd_file = ICMS_ROOT_PATH . "/modules/{$module_dir}/class/{$name}.php";
}
// Try alternative class naming patterns with autoloading
$alternativeClass = ucfirst(strtolower($module_basename)) . ucfirst($name) . 'Handler';
if (class_exists($alternativeClass)) {
$handlers[$module_dir][$name] = new $alternativeClass(icms::$xoopsDB);
} else {
$hnd_file = ICMS_ROOT_PATH . "/modules/{$module_dir}/admin/{$name}/class/{$name}.php";
}
if (file_exists($hnd_file)) {include_once $hnd_file;}
$class = ucfirst(strtolower($module_basename)) . ucfirst($name) . 'Handler';
if (class_exists($class)) {
$handlers[$module_dir][$name] = new $class(icms::$xoopsDB);
// Fallback to manual include for legacy modules not yet using autoloading
if($module_dir !== 'system') {
if (!file_exists($hnd_file = ICMS_ROOT_PATH . "/modules/{$module_dir}/class/". ucfirst(strtolower($name)) ."Handler.php")) {
$hnd_file = ICMS_ROOT_PATH . "/modules/{$module_dir}/class/{$name}.php";
}
} else {
$hnd_file = ICMS_ROOT_PATH . "/modules/{$module_dir}/admin/{$name}/class/{$name}.php";
}
if (file_exists($hnd_file)) {
include_once $hnd_file;
if (class_exists($alternativeClass)) {
$handlers[$module_dir][$name] = new $alternativeClass(icms::$xoopsDB);
}
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions htdocs/install/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,21 @@
require_once 'include/functions.php';
include_once './class/IcmsInstallWizard.php';

// Initialize the modern autoloading system
if (file_exists('../vendor/autoload.php')) {
require_once '../vendor/autoload.php';
}

// Load the compatibility bridge
require_once '../libraries/icms/ComposerAutoloadBridge.php';

// Initialize legacy autoloader for backward compatibility
require_once '../libraries/icms/Autoloader.php';
icms_Autoloader::setup();

// Initialize the bridge
icms_ComposerAutoloadBridge::initialize();

error_reporting(E_ALL);

$pageHasHelp = false;
Expand Down
28 changes: 25 additions & 3 deletions htdocs/libraries/icms.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,35 @@ static public function setup() {
self::$paths['www'] = array(ICMS_ROOT_PATH, ICMS_URL);
self::$paths['modules'] = array(ICMS_ROOT_PATH . '/modules', ICMS_URL . '/modules');
self::$paths['themes'] = array(ICMS_THEME_PATH, ICMS_THEME_URL);
// Initialize the autoloader
require_once dirname(__FILE__ ) . '/icms/Autoloader.php';
icms_Autoloader::setup();

// Initialize autoloading system
self::initializeAutoloading();

register_shutdown_function(array(__CLASS__, 'shutdown'));
self::buildRelevantUrls();
}

/**
* Initialize the autoloading system with Composer and legacy support
*/
static private function initializeAutoloading() {
// Try to load Composer autoloader first - now located in htdocs/vendor/
$composerAutoloadPath = ICMS_ROOT_PATH . '/vendor/autoload.php';
if (file_exists($composerAutoloadPath)) {
require_once $composerAutoloadPath;
}

// Load the compatibility bridge
require_once dirname(__FILE__) . '/icms/ComposerAutoloadBridge.php';

// Initialize legacy autoloader for backward compatibility
require_once dirname(__FILE__) . '/icms/Autoloader.php';
icms_Autoloader::setup();

// Initialize the bridge
icms_ComposerAutoloadBridge::initialize();
}

/**
* Launch bootstrap and instanciate global services
* @return void
Expand Down
212 changes: 212 additions & 0 deletions htdocs/libraries/icms/AutoloadPerformanceMonitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?php
/**
* ImpressCMS Autoload Performance Monitor
*
* This class provides performance monitoring and optimization tools
* for the autoloading system.
*
* @copyright http://www.impresscms.org/ The ImpressCMS Project
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @category ICMS
* @package Core
* @since 1.5
*/

class icms_AutoloadPerformanceMonitor {

/**
* Performance metrics
* @var array
*/
private static $metrics = array(
'class_loads' => 0,
'load_times' => array(),
'failed_loads' => 0,
'cache_hits' => 0,
'cache_misses' => 0
);

/**
* Whether monitoring is enabled
* @var bool
*/
private static $enabled = false;

/**
* Start performance monitoring
*/
public static function enable() {
if (!self::$enabled) {
self::$enabled = true;
self::registerMonitoringAutoloader();
}
}

/**
* Stop performance monitoring
*/
public static function disable() {
self::$enabled = false;
}

/**
* Register a monitoring autoloader
*/
private static function registerMonitoringAutoloader() {
spl_autoload_register(array(__CLASS__, 'monitoringAutoloader'), true, true);
}

/**
* Monitoring autoloader that tracks performance
*
* @param string $class The class name
* @return bool
*/
public static function monitoringAutoloader($class) {
if (!self::$enabled) {
return false;
}

$startTime = microtime(true);

// Let other autoloaders handle the actual loading
$loaded = false;
$autoloaders = spl_autoload_functions();

foreach ($autoloaders as $autoloader) {
if ($autoloader === array(__CLASS__, 'monitoringAutoloader')) {
continue; // Skip ourselves
}

if (is_callable($autoloader)) {
if (call_user_func($autoloader, $class)) {
$loaded = true;
break;
}
}
}

$endTime = microtime(true);
$loadTime = ($endTime - $startTime) * 1000; // Convert to milliseconds

// Record metrics
if ($loaded) {
self::$metrics['class_loads']++;
self::$metrics['load_times'][] = $loadTime;

// Check if it was a cache hit (very fast load)
if ($loadTime < 0.1) {
self::$metrics['cache_hits']++;
} else {
self::$metrics['cache_misses']++;
}
} else {
self::$metrics['failed_loads']++;
}

return $loaded;
}

/**
* Get performance metrics
*
* @return array
*/
public static function getMetrics() {
$metrics = self::$metrics;

if (!empty($metrics['load_times'])) {
$metrics['average_load_time'] = array_sum($metrics['load_times']) / count($metrics['load_times']);
$metrics['max_load_time'] = max($metrics['load_times']);
$metrics['min_load_time'] = min($metrics['load_times']);
}

$metrics['cache_hit_ratio'] = 0;
if (($metrics['cache_hits'] + $metrics['cache_misses']) > 0) {
$metrics['cache_hit_ratio'] = $metrics['cache_hits'] / ($metrics['cache_hits'] + $metrics['cache_misses']);
}

return $metrics;
}

/**
* Reset performance metrics
*/
public static function resetMetrics() {
self::$metrics = array(
'class_loads' => 0,
'load_times' => array(),
'failed_loads' => 0,
'cache_hits' => 0,
'cache_misses' => 0
);
}

/**
* Generate a performance report
*
* @return string
*/
public static function generateReport() {
$metrics = self::getMetrics();

$report = "ImpressCMS Autoload Performance Report\n";
$report .= "=====================================\n\n";

$report .= "Classes Loaded: " . $metrics['class_loads'] . "\n";
$report .= "Failed Loads: " . $metrics['failed_loads'] . "\n";
$report .= "Cache Hits: " . $metrics['cache_hits'] . "\n";
$report .= "Cache Misses: " . $metrics['cache_misses'] . "\n";
$report .= "Cache Hit Ratio: " . number_format($metrics['cache_hit_ratio'] * 100, 2) . "%\n\n";

if (isset($metrics['average_load_time'])) {
$report .= "Average Load Time: " . number_format($metrics['average_load_time'], 3) . "ms\n";
$report .= "Max Load Time: " . number_format($metrics['max_load_time'], 3) . "ms\n";
$report .= "Min Load Time: " . number_format($metrics['min_load_time'], 3) . "ms\n\n";
}

// Performance recommendations
$report .= "Recommendations:\n";
$report .= "----------------\n";

if ($metrics['cache_hit_ratio'] < 0.8) {
$report .= "- Consider enabling APCu for better caching performance\n";
$report .= "- Run 'composer optimize-production' for production environments\n";
}

if (isset($metrics['average_load_time']) && $metrics['average_load_time'] > 1.0) {
$report .= "- Average load time is high, consider optimizing autoloader\n";
$report .= "- Check for unnecessary file system operations\n";
}

if ($metrics['failed_loads'] > 0) {
$report .= "- " . $metrics['failed_loads'] . " failed loads detected, check class naming\n";
}

return $report;
}

/**
* Check if autoloader optimizations are available
*
* @return array
*/
public static function checkOptimizations() {
$optimizations = array();

// Check for APCu
$optimizations['apcu_available'] = extension_loaded('apcu') && apcu_enabled();

// Check for Composer optimizations
$optimizations['composer_optimized'] = false;
if (file_exists(ICMS_ROOT_PATH . '/vendor/composer/autoload_classmap.php')) {
$classmap = include ICMS_ROOT_PATH . '/vendor/composer/autoload_classmap.php';
$optimizations['composer_optimized'] = !empty($classmap);
}

// Check for production mode
$optimizations['production_mode'] = !defined('ICMS_DEBUG') || !ICMS_DEBUG;

return $optimizations;
}
}
Loading