Skip to content

Commit 64d6db6

Browse files
Merge pull request #9033 from Sesquipedalian/3.0/integrate_autoload
[3.0] Fixes the integrate_autoload hook
2 parents aa69300 + df9b3ad commit 64d6db6

File tree

5 files changed

+63
-30
lines changed

5 files changed

+63
-30
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

composer.json

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
{
2-
"name": "simplemachines/smf",
3-
"repositories": [
4-
{
5-
"url": "https://github.com/SimpleMachines/BuildTools.git",
6-
"type": "vcs"
7-
}
8-
],
2+
"name": "simplemachines/smf",
3+
"repositories": [
4+
{
5+
"url": "https://github.com/SimpleMachines/BuildTools.git",
6+
"type": "vcs"
7+
}
8+
],
99
"autoload": {
1010
"psr-4": {
11-
"SMF\\": "Sources/"
11+
"SMF\\": "Sources/",
12+
"SMF\\Themes\\": "Themes/"
13+
}
14+
},
15+
"minimum-stability": "dev",
16+
"prefer-stable": true,
17+
"require-dev": {
18+
"simplemachines/build-tools": "dev-release-3.0",
19+
"friendsofphp/php-cs-fixer": "^3.40"
20+
},
21+
"scripts": {
22+
"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",
23+
"lint-fix": "php-cs-fixer fix -v --config .php-cs-fixer.dist.php --path-mode=intersection $(git diff --name-only \"*.php\") --allow-risky=yes"
24+
},
25+
"config": {
26+
"platform": {
27+
"php": "8.0.0"
1228
}
1329
},
14-
"minimum-stability": "dev",
15-
"prefer-stable": true,
16-
"require-dev": {
17-
"simplemachines/build-tools": "dev-release-3.0",
18-
"friendsofphp/php-cs-fixer": "^3.40"
19-
},
20-
"scripts": {
21-
"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",
22-
"lint-fix": "php-cs-fixer fix -v --config .php-cs-fixer.dist.php --path-mode=intersection $(git diff --name-only \"*.php\") --allow-risky=yes"
23-
},
24-
"config": {
25-
"platform": {
26-
"php": "8.0.0"
27-
}
28-
},
2930
"require": {
3031
"google/recaptcha": "^1.3",
3132
"matthiasmullie/minify": "^1.3",
3233
"bjeavons/zxcvbn-php": "^1.0",
33-
"matthiasmullie/path-converter": "^1.1"
34+
"matthiasmullie/path-converter": "^1.1"
3435
}
3536
}

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)