From 0abb2e6b9aa45b8376ea516dcd995579e2f48724 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 16 May 2024 23:31:47 +0800 Subject: [PATCH] MDL-81919 core: Update moved file namespaces --- .upgradenotes/MDL-81919-1715909143241.yml | 19 +++++++++++++ lib/classes/component.php | 5 +--- lib/classes/exception/coding_exception.php | 9 +++++- .../exception/file_serving_exception.php | 8 +++++- .../invalid_dataroot_permissions.php | 8 +++++- .../exception/invalid_parameter_exception.php | 9 +++++- .../exception/invalid_response_exception.php | 9 +++++- .../exception/invalid_state_exception.php | 9 +++++- lib/classes/exception/moodle_exception.php | 9 +++++- .../exception/require_login_exception.php | 8 ++++++ ...equire_login_session_timeout_exception.php | 8 ++++++ .../required_capability_exception.php | 10 ++++++- .../webservice_parameter_exception.php | 10 +++++-- lib/classes/output/bootstrap_renderer.php | 28 +++++++++++++------ 14 files changed, 126 insertions(+), 23 deletions(-) create mode 100644 .upgradenotes/MDL-81919-1715909143241.yml diff --git a/.upgradenotes/MDL-81919-1715909143241.yml b/.upgradenotes/MDL-81919-1715909143241.yml new file mode 100644 index 00000000000..ee14240307a --- /dev/null +++ b/.upgradenotes/MDL-81919-1715909143241.yml @@ -0,0 +1,19 @@ +issueNumber: MDL-81919 +notes: + core: + - message: > + The following exceptions are now also available in the `\core\exception` + namespace: + + - `\coding_exception` + - `\file_serving_exception` + - `\invalid_dataroot_permissions` + - `\invalid_parameter_exception` + - `\invalid_response_exception` + - `\invalid_state_exception` + - `\moodle_exception` + - `\require_login_exception` + - `\require_login_session_timeout_exception` + - `\required_capability_exception` + - `\webservice_parameter_exception` + type: improved diff --git a/lib/classes/component.php b/lib/classes/component.php index ae12e1a52ae..744a26b1e51 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -1423,10 +1423,7 @@ $cache = ' . var_export($cache, true) . '; require($file); if (is_array($legacyclasses)) { foreach ($legacyclasses as $classname => $path) { - $fullpath = "{$fulldir}/classes/{$path}"; - if (file_exists($fullpath)) { - self::$classmap[$classname] = $fullpath; - } + self::$classmap[$classname] = "{$fulldir}/classes/{$path}"; } } } diff --git a/lib/classes/exception/coding_exception.php b/lib/classes/exception/coding_exception.php index 677620df799..43c29e7af95 100644 --- a/lib/classes/exception/coding_exception.php +++ b/lib/classes/exception/coding_exception.php @@ -14,12 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; + /** * Exception indicating programming error, must be fixed by a programer. For example * a core API might throw this type of exception if a plugin calls it incorrectly. * * @package core - * @subpackage lib + * @subpackage exception * @copyright 2008 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -34,3 +36,8 @@ class coding_exception extends moodle_exception { parent::__construct('codingerror', 'debug', '', $hint, $debuginfo); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(coding_exception::class, \coding_exception::class); diff --git a/lib/classes/exception/file_serving_exception.php b/lib/classes/exception/file_serving_exception.php index adccfa1a340..0c5950ef717 100644 --- a/lib/classes/exception/file_serving_exception.php +++ b/lib/classes/exception/file_serving_exception.php @@ -14,12 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; /** * An exception that indicates that file can not be served * * @package core - * @subpackage lib + * @subpackage exception * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -33,3 +34,8 @@ class file_serving_exception extends moodle_exception { parent::__construct('cannotservefile', 'error', '', null, $debuginfo); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(file_serving_exception::class, \file_serving_exception::class); diff --git a/lib/classes/exception/invalid_dataroot_permissions.php b/lib/classes/exception/invalid_dataroot_permissions.php index 2f39de58fee..2ef0cfe104f 100644 --- a/lib/classes/exception/invalid_dataroot_permissions.php +++ b/lib/classes/exception/invalid_dataroot_permissions.php @@ -14,12 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; /** * An exception that indicates incorrect permissions in $CFG->dataroot * * @package core - * @subpackage lib + * @subpackage exception * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -33,3 +34,8 @@ class invalid_dataroot_permissions extends moodle_exception { parent::__construct('invaliddatarootpermissions', 'error', '', null, $debuginfo); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(invalid_dataroot_permissions::class, \invalid_dataroot_permissions::class); diff --git a/lib/classes/exception/invalid_parameter_exception.php b/lib/classes/exception/invalid_parameter_exception.php index 5aa8a4f1a05..687b2f5956d 100644 --- a/lib/classes/exception/invalid_parameter_exception.php +++ b/lib/classes/exception/invalid_parameter_exception.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; + /** * Exception indicating malformed parameter problem. * This exception is not supposed to be thrown when processing @@ -21,7 +23,7 @@ * for WS and other low level stuff. * * @package core - * @subpackage lib + * @subpackage exception * @copyright 2009 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -35,3 +37,8 @@ class invalid_parameter_exception extends moodle_exception { parent::__construct('invalidparameter', 'debug', '', null, $debuginfo); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(invalid_parameter_exception::class, \invalid_parameter_exception::class); diff --git a/lib/classes/exception/invalid_response_exception.php b/lib/classes/exception/invalid_response_exception.php index 03082713e3d..05774f14e9f 100644 --- a/lib/classes/exception/invalid_response_exception.php +++ b/lib/classes/exception/invalid_response_exception.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; + /** * Exception indicating malformed response problem. * This exception is not supposed to be thrown when processing @@ -21,7 +23,7 @@ * for WS and other low level stuff. * * @package core - * @subpackage lib + * @subpackage exception * @copyright Jerome Mounerac * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -35,3 +37,8 @@ class invalid_response_exception extends moodle_exception { parent::__construct('invalidresponse', 'debug', '', null, $debuginfo); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(invalid_response_exception::class, \invalid_response_exception::class); diff --git a/lib/classes/exception/invalid_state_exception.php b/lib/classes/exception/invalid_state_exception.php index 47ee19a5aff..89d2bf10126 100644 --- a/lib/classes/exception/invalid_state_exception.php +++ b/lib/classes/exception/invalid_state_exception.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; + /** * An exception that indicates something really weird happened. For example, * if you do switch ($context->contextlevel), and have one case for each @@ -22,7 +24,7 @@ * $context->contextlevel is invalid - rather than ignoring this possibility. * * @package core - * @subpackage lib + * @subpackage exception * @copyright 2009 onwards Martin Dougiamas {@link http://moodle.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -37,3 +39,8 @@ class invalid_state_exception extends moodle_exception { parent::__construct('invalidstatedetected', 'debug', '', $hint, $debuginfo); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(invalid_state_exception::class, \invalid_state_exception::class); diff --git a/lib/classes/exception/moodle_exception.php b/lib/classes/exception/moodle_exception.php index cff748790bc..2546a82b518 100644 --- a/lib/classes/exception/moodle_exception.php +++ b/lib/classes/exception/moodle_exception.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; + /** * Base Moodle Exception class * @@ -21,7 +23,7 @@ * after moodlelib.php has been included (which will happen very soon). * * @package core - * @subpackage lib + * @subpackage exception * @copyright 2008 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -99,3 +101,8 @@ class moodle_exception extends \Exception { parent::__construct($message, 0); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(moodle_exception::class, \moodle_exception::class); diff --git a/lib/classes/exception/require_login_exception.php b/lib/classes/exception/require_login_exception.php index 5eadb688e2f..a6961d93023 100644 --- a/lib/classes/exception/require_login_exception.php +++ b/lib/classes/exception/require_login_exception.php @@ -14,12 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; + /** * Course/activity access exception. * * This exception is thrown from require_login() * * @package core + * @subpackage exception * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -33,3 +36,8 @@ class require_login_exception extends moodle_exception { parent::__construct('requireloginerror', 'error', '', null, $debuginfo); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(require_login_exception::class, \require_login_exception::class); diff --git a/lib/classes/exception/require_login_session_timeout_exception.php b/lib/classes/exception/require_login_session_timeout_exception.php index 56c70509a61..9e3e243e85d 100644 --- a/lib/classes/exception/require_login_session_timeout_exception.php +++ b/lib/classes/exception/require_login_session_timeout_exception.php @@ -14,12 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; + /** * Session timeout exception. * * This exception is thrown from require_login() * * @package core + * @subpackage exception * @copyright 2015 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -31,3 +34,8 @@ class require_login_session_timeout_exception extends require_login_exception { moodle_exception::__construct('sessionerroruser', 'error'); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(require_login_session_timeout_exception::class, \require_login_session_timeout_exception::class); diff --git a/lib/classes/exception/required_capability_exception.php b/lib/classes/exception/required_capability_exception.php index da8a9062d68..84642162146 100644 --- a/lib/classes/exception/required_capability_exception.php +++ b/lib/classes/exception/required_capability_exception.php @@ -14,11 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\exception; + /** * Exceptions indicating user does not have permissions to do something * and the execution can not continue. * * @package core + * @subpackage exception * @copyright 2009 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -26,7 +29,7 @@ class required_capability_exception extends moodle_exception { /** * Constructor. * - * @param context $context The context used for the capability check + * @param \core\context $context The context used for the capability check * @param string $capability The required capability * @param string $errormessage The error message to show the user * @param string $stringfile @@ -44,3 +47,8 @@ class required_capability_exception extends moodle_exception { parent::__construct($errormessage, $stringfile, $link, $capabilityname); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(required_capability_exception::class, \required_capability_exception::class); diff --git a/lib/classes/exception/webservice_parameter_exception.php b/lib/classes/exception/webservice_parameter_exception.php index a2b5165ea8c..0efd5c2a084 100644 --- a/lib/classes/exception/webservice_parameter_exception.php +++ b/lib/classes/exception/webservice_parameter_exception.php @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . - +namespace core\exception; /** * Web service parameter exception class. * @@ -22,7 +22,8 @@ * This exception must be thrown to the web service client when a web service parameter is invalid * The error string is gotten from webservice.php * @package core - * @copyright Jerome Mouneray + * @subpackage exception + * @copyright Jerome Mounerac * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class webservice_parameter_exception extends moodle_exception { @@ -37,3 +38,8 @@ class webservice_parameter_exception extends moodle_exception { parent::__construct($errorcode, 'webservice', '', $a, $debuginfo); } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(webservice_parameter_exception::class, \webservice_parameter_exception::class); diff --git a/lib/classes/output/bootstrap_renderer.php b/lib/classes/output/bootstrap_renderer.php index 8ad880d588f..b889a87b57f 100644 --- a/lib/classes/output/bootstrap_renderer.php +++ b/lib/classes/output/bootstrap_renderer.php @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core\output; + +use coding_exception; + /** * This class solves the problem of how to initialise $OUTPUT. * @@ -109,7 +113,7 @@ class bootstrap_renderer { // Too soon to initialise $OUTPUT, provide a couple of key methods. if (array_key_exists($method, $earlymethods)) { - return call_user_func_array(['bootstrap_renderer', $earlymethods[$method]], $arguments); + return call_user_func_array([self::class, $earlymethods[$method]], $arguments); } throw new coding_exception('Attempt to start output before enough information is known to initialise the theme.'); @@ -184,21 +188,22 @@ class bootstrap_renderer { } return; } else if (AJAX_SCRIPT) { - $e = new stdClass(); - $e->error = $message; - $e->stacktrace = null; - $e->debuginfo = null; + $error = (object) [ + 'error' => $message, + 'stacktrace' => null, + 'debuginfo' => null, + 'errorcode' => $errorcode, + ]; if (!empty($CFG->debug) && $CFG->debug >= DEBUG_DEVELOPER) { if (!empty($debuginfo)) { - $e->debuginfo = $debuginfo; + $error->debuginfo = $debuginfo; } if (!empty($backtrace)) { - $e->stacktrace = format_backtrace($backtrace, true); + $error->stacktrace = format_backtrace($backtrace, true); } } - $e->errorcode = $errorcode; @header('Content-Type: application/json; charset=utf-8'); - echo json_encode($e); + echo json_encode($error); return; } @@ -300,3 +305,8 @@ class bootstrap_renderer { return $html; } } + +// Alias this class to the old name. +// This file will be autoloaded by the legacyclasses autoload system. +// In future all uses of this class will be corrected and the legacy references will be removed. +class_alias(bootstrap_renderer::class, \bootstrap_renderer::class);