Skip to content

Commit 0d689e2

Browse files
Fixes the integrate_autoload hook
Signed-off-by: Jon Stovell <[email protected]>
1 parent aa69300 commit 0d689e2

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

Sources/Config.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ class Config
254254
public static string $sourcedir;
255255

256256
/**
257+
* @var string
258+
*
257259
* Path to where our dependencies are located.
258260
*/
259261
public static string $vendordir;
@@ -322,6 +324,14 @@ class Config
322324
*/
323325
public static string $scripturl;
324326

327+
/**
328+
* @var \Composer\Autoload\ClassLoader
329+
*
330+
* Autoloader instance.
331+
* This is used to support the integrate_autoload hook.
332+
*/
333+
public static \Composer\Autoload\ClassLoader $loader;
334+
325335
/****************************
326336
* Internal static properties
327337
****************************/
@@ -1136,6 +1146,18 @@ public static function reloadModSettings(): void
11361146
die('SMF file version (' . SMF_VERSION . ') does not match SMF database version (' . self::$modSettings['smfVersion'] . ').<br>Run the SMF upgrader to fix this.<br><a href="https://wiki.simplemachines.org/smf/Upgrading">More information</a>.');
11371147
}
11381148

1149+
// Any autoloader integrations to add?
1150+
if (isset(self::$modSettings['integrate_autoload'])) {
1151+
$class_map = [];
1152+
1153+
IntegrationHook::call('integrate_autoload', [&$class_map]);
1154+
1155+
foreach ($class_map as $prefix => $dirname) {
1156+
self::$loader->addPsr4($prefix, $dirname);
1157+
}
1158+
}
1159+
1160+
// Ensure the cache_enable setting reflects reality.
11391161
self::$modSettings['cache_enable'] = Cache\CacheApi::$enable;
11401162

11411163
// Used to force browsers to download fresh CSS and JavaScript when necessary

index.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,11 @@
122122
require_once $sourcedir . DIRECTORY_SEPARATOR . 'Config.php';
123123
SMF\Config::set(get_defined_vars());
124124

125-
$loader = require SMF\Config::$vendordir . '/autoload.php';
125+
// Start up the autoloader.
126+
SMF\Config::$loader = require SMF\Config::$vendordir . '/autoload.php';
126127

127-
if (isset(SMF\Config::$modSettings['integrate_autoload'])) {
128-
foreach (explode(',', SMF\Config::$modSettings['integrate_autoload']) as $prefix => $dirname) {
129-
$loader->addPsr4($prefix, $dirname);
130-
}
131-
}
128+
// Ensure the SMF namespace points to $sourcedir.
129+
SMF\Config::$loader->setPsr4('SMF\\', $sourcedir);
132130

133131
// Ensure $db_last_error is set, too.
134132
SMF\Config::getDbLastError();

other/Settings.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@
208208
* Path to the Packages directory.
209209
*/
210210
$packagesdir = __DIR__ . '/Packages';
211+
/**
212+
* @var string
213+
*
214+
* Path to where our dependencies are located.
215+
*/
216+
$vendordir = __DIR__ . '/vendor';
211217
/**
212218
* @var string
213219
*

other/Settings_bak.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@
208208
* Path to the Packages directory.
209209
*/
210210
$packagesdir = __DIR__ . '/Packages';
211+
/**
212+
* @var string
213+
*
214+
* Path to where our dependencies are located.
215+
*/
216+
$vendordir = __DIR__ . '/vendor';
211217
/**
212218
* @var string
213219
*

0 commit comments

Comments
 (0)