diff --git a/Sources/Config.php b/Sources/Config.php index 2228391bbb9..d58179849f2 100644 --- a/Sources/Config.php +++ b/Sources/Config.php @@ -254,6 +254,8 @@ class Config public static string $sourcedir; /** + * @var string + * * Path to where our dependencies are located. */ public static string $vendordir; @@ -322,6 +324,14 @@ class Config */ public static string $scripturl; + /** + * @var \Composer\Autoload\ClassLoader + * + * Autoloader instance. + * This is used to support the integrate_autoload hook. + */ + public static \Composer\Autoload\ClassLoader $loader; + /**************************** * Internal static properties ****************************/ @@ -1136,6 +1146,18 @@ public static function reloadModSettings(): void die('SMF file version (' . SMF_VERSION . ') does not match SMF database version (' . self::$modSettings['smfVersion'] . ').
Run the SMF upgrader to fix this.
More information.'); } + // Any autoloader integrations to add? + if (isset(self::$modSettings['integrate_autoload'])) { + $class_map = []; + + IntegrationHook::call('integrate_autoload', [&$class_map]); + + foreach ($class_map as $prefix => $dirname) { + self::$loader->addPsr4($prefix, $dirname); + } + } + + // Ensure the cache_enable setting reflects reality. self::$modSettings['cache_enable'] = Cache\CacheApi::$enable; // Used to force browsers to download fresh CSS and JavaScript when necessary diff --git a/composer.json b/composer.json index 37d8ad06929..7c04e8affd7 100644 --- a/composer.json +++ b/composer.json @@ -1,35 +1,36 @@ { - "name": "simplemachines/smf", - "repositories": [ - { - "url": "https://github.com/SimpleMachines/BuildTools.git", - "type": "vcs" - } - ], + "name": "simplemachines/smf", + "repositories": [ + { + "url": "https://github.com/SimpleMachines/BuildTools.git", + "type": "vcs" + } + ], "autoload": { "psr-4": { - "SMF\\": "Sources/" + "SMF\\": "Sources/", + "SMF\\Themes\\": "Themes/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "require-dev": { + "simplemachines/build-tools": "dev-release-3.0", + "friendsofphp/php-cs-fixer": "^3.40" + }, + "scripts": { + "lint": "php-cs-fixer --quiet check --config .php-cs-fixer.dist.php --path-mode=intersection $(git diff --name-only \"*.php\") || php-cs-fixer check --diff --config .php-cs-fixer.dist.php --path-mode=intersection $(git diff --name-only \"*.php\") --allow-risky=yes", + "lint-fix": "php-cs-fixer fix -v --config .php-cs-fixer.dist.php --path-mode=intersection $(git diff --name-only \"*.php\") --allow-risky=yes" + }, + "config": { + "platform": { + "php": "8.0.0" } }, - "minimum-stability": "dev", - "prefer-stable": true, - "require-dev": { - "simplemachines/build-tools": "dev-release-3.0", - "friendsofphp/php-cs-fixer": "^3.40" - }, - "scripts": { - "lint": "php-cs-fixer --quiet check --config .php-cs-fixer.dist.php --path-mode=intersection $(git diff --name-only \"*.php\") || php-cs-fixer check --diff --config .php-cs-fixer.dist.php --path-mode=intersection $(git diff --name-only \"*.php\") --allow-risky=yes", - "lint-fix": "php-cs-fixer fix -v --config .php-cs-fixer.dist.php --path-mode=intersection $(git diff --name-only \"*.php\") --allow-risky=yes" - }, - "config": { - "platform": { - "php": "8.0.0" - } - }, "require": { "google/recaptcha": "^1.3", "matthiasmullie/minify": "^1.3", "bjeavons/zxcvbn-php": "^1.0", - "matthiasmullie/path-converter": "^1.1" + "matthiasmullie/path-converter": "^1.1" } } diff --git a/index.php b/index.php index d8169347096..8e07434b717 100644 --- a/index.php +++ b/index.php @@ -122,13 +122,11 @@ require_once $sourcedir . DIRECTORY_SEPARATOR . 'Config.php'; SMF\Config::set(get_defined_vars()); - $loader = require SMF\Config::$vendordir . '/autoload.php'; + // Start up the autoloader. + SMF\Config::$loader = require SMF\Config::$vendordir . '/autoload.php'; - if (isset(SMF\Config::$modSettings['integrate_autoload'])) { - foreach (explode(',', SMF\Config::$modSettings['integrate_autoload']) as $prefix => $dirname) { - $loader->addPsr4($prefix, $dirname); - } - } + // Ensure the SMF namespace points to $sourcedir. + SMF\Config::$loader->setPsr4('SMF\\', $sourcedir); // Ensure $db_last_error is set, too. SMF\Config::getDbLastError(); diff --git a/other/Settings.php b/other/Settings.php index be055e45a89..767ea48a5d9 100644 --- a/other/Settings.php +++ b/other/Settings.php @@ -208,6 +208,12 @@ * Path to the Packages directory. */ $packagesdir = __DIR__ . '/Packages'; +/** + * @var string + * + * Path to where our dependencies are located. + */ +$vendordir = __DIR__ . '/vendor'; /** * @var string * diff --git a/other/Settings_bak.php b/other/Settings_bak.php index e4f02b11f1d..49e242a1ed4 100644 --- a/other/Settings_bak.php +++ b/other/Settings_bak.php @@ -208,6 +208,12 @@ * Path to the Packages directory. */ $packagesdir = __DIR__ . '/Packages'; +/** + * @var string + * + * Path to where our dependencies are located. + */ +$vendordir = __DIR__ . '/vendor'; /** * @var string *