From e17dd3bf62c2005d58def6d49938aa7f2e08765d Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 5 Feb 2025 20:07:42 +0800 Subject: [PATCH] MDL-83757 core: Force DI to use global DB instead of scoped --- lib/classes/di.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/classes/di.php b/lib/classes/di.php index 97404a42bef..e861b4d7451 100644 --- a/lib/classes/di.php +++ b/lib/classes/di.php @@ -84,7 +84,7 @@ class di { * @return ContainerInterface */ protected static function create_container(): ContainerInterface { - global $CFG, $DB; + global $CFG; // PHP Does not support function autoloading. We must manually include the file. require_once("{$CFG->libdir}/php-di/php-di/src/functions.php"); @@ -113,7 +113,11 @@ class di { \core\hook\manager::class => $hookmanager, // The database. - \moodle_database::class => $DB, + \moodle_database::class => function(): \moodle_database { + global $DB; + + return $DB; + }, // The string manager. \core_string_manager::class => fn() => get_string_manager(),