MDL-81919 core: Update moved file namespaces

This commit is contained in:
Andrew Nicols
2024-06-10 12:13:00 +08:00
parent 75e8dbb3c5
commit 0abb2e6b9a
14 changed files with 126 additions and 23 deletions
+19
View File
@@ -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
+1 -4
View File
@@ -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}";
}
}
}
+8 -1
View File
@@ -14,12 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
@@ -14,12 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
@@ -14,12 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
+8 -1
View File
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
@@ -14,12 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
@@ -14,12 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\exception;
/**
* Session timeout exception.
*
* This exception is thrown from require_login()
*
* @package core
* @subpackage exception
* @copyright 2015 Andrew Nicols <[email protected]>
* @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);
@@ -14,11 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);
+19 -9
View File
@@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
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);