mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-81919 core: Fix coding style issues for recently moved code
This commit is contained in:
parent
8c3f18a4eb
commit
75e8dbb3c5
lib/classes
exception
coding_exception.phpfile_serving_exception.phpinvalid_dataroot_permissions.phpinvalid_parameter_exception.phpinvalid_response_exception.phpinvalid_state_exception.phpmoodle_exception.phprequire_login_exception.phprequire_login_session_timeout_exception.phprequired_capability_exception.phpwebservice_parameter_exception.php
output
@ -25,11 +25,12 @@
|
||||
*/
|
||||
class coding_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $hint short description of problem
|
||||
* @param string $debuginfo detailed information how to fix problem
|
||||
*/
|
||||
function __construct($hint, $debuginfo=null) {
|
||||
public function __construct($hint, $debuginfo = null) {
|
||||
parent::__construct('codingerror', 'debug', '', $hint, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,11 @@
|
||||
*/
|
||||
class file_serving_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $debuginfo optional more detailed information
|
||||
*/
|
||||
function __construct($debuginfo = NULL) {
|
||||
parent::__construct('cannotservefile', 'error', '', NULL, $debuginfo);
|
||||
public function __construct($debuginfo = null) {
|
||||
parent::__construct('cannotservefile', 'error', '', null, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,11 @@
|
||||
*/
|
||||
class invalid_dataroot_permissions extends moodle_exception {
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $debuginfo optional more detailed information
|
||||
*/
|
||||
function __construct($debuginfo = NULL) {
|
||||
parent::__construct('invaliddatarootpermissions', 'error', '', NULL, $debuginfo);
|
||||
public function __construct($debuginfo = null) {
|
||||
parent::__construct('invaliddatarootpermissions', 'error', '', null, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
@ -27,10 +27,11 @@
|
||||
*/
|
||||
class invalid_parameter_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $debuginfo some detailed information
|
||||
*/
|
||||
function __construct($debuginfo=null) {
|
||||
public function __construct($debuginfo = null) {
|
||||
parent::__construct('invalidparameter', 'debug', '', null, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,19 @@
|
||||
* This exception is not supposed to be thrown when processing
|
||||
* user submitted data in forms. It is more suitable
|
||||
* for WS and other low level stuff.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage lib
|
||||
* @copyright Jerome Mounerac
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class invalid_response_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $debuginfo some detailed information
|
||||
*/
|
||||
function __construct($debuginfo=null) {
|
||||
public function __construct($debuginfo = null) {
|
||||
parent::__construct('invalidresponse', 'debug', '', null, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,12 @@
|
||||
*/
|
||||
class invalid_state_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $hint short description of problem
|
||||
* @param string $debuginfo optional more detailed information
|
||||
*/
|
||||
function __construct($hint, $debuginfo=null) {
|
||||
public function __construct($hint, $debuginfo = null) {
|
||||
parent::__construct('invalidstatedetected', 'debug', '', $hint, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
@ -26,41 +26,35 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class moodle_exception extends \Exception {
|
||||
|
||||
/**
|
||||
* @var string The name of the string from error.php to print
|
||||
*/
|
||||
/** @var string The name of the string from error.php to print */
|
||||
public $errorcode;
|
||||
|
||||
/**
|
||||
* @var string The name of module
|
||||
*/
|
||||
/** @var string The name of module */
|
||||
public $module;
|
||||
|
||||
/**
|
||||
* @var mixed Extra words and phrases that might be required in the error string
|
||||
*/
|
||||
/** @var mixed Extra words and phrases that might be required in the error string */
|
||||
public $a;
|
||||
|
||||
/**
|
||||
* @var string The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
|
||||
* The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $link;
|
||||
|
||||
/**
|
||||
* @var string Optional information to aid the debugging process
|
||||
*/
|
||||
/** @var string Optional information to aid the debugging process */
|
||||
public $debuginfo;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string $errorcode The name of the string from error.php to print
|
||||
* @param string $module name of module
|
||||
* @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
|
||||
* @param string $link The url where the user will be prompted to continue.
|
||||
* If no url is provided the user will be directed to the site index page.
|
||||
* @param mixed $a Extra words and phrases that might be required in the error string
|
||||
* @param string $debuginfo optional debugging information
|
||||
*/
|
||||
function __construct($errorcode, $module='', $link='', $a=NULL, $debuginfo=null) {
|
||||
public function __construct($errorcode, $module = '', $link = '', $a = null, $debuginfo = null) {
|
||||
global $CFG;
|
||||
|
||||
if (empty($module) || $module == 'moodle' || $module == 'core') {
|
||||
@ -95,11 +89,11 @@ class moodle_exception extends \Exception {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$haserrorstring and $isinphpunittest) {
|
||||
if (!$haserrorstring && $isinphpunittest) {
|
||||
// Append the contents of $a to $debuginfo so helpful information isn't lost.
|
||||
// This emulates what {@link get_exception_info()} does. Unfortunately that
|
||||
// function is not used by phpunit.
|
||||
$message .= PHP_EOL.'$a contents: '.print_r($a, true);
|
||||
$message .= PHP_EOL . '$a contents: ' . print_r($a, true); // phpcs:ignore moodle.PHP.ForbiddenFunctions.Found
|
||||
}
|
||||
|
||||
parent::__construct($message, 0);
|
||||
|
@ -19,16 +19,17 @@
|
||||
*
|
||||
* This exception is thrown from require_login()
|
||||
*
|
||||
* @package core_access
|
||||
* @package core
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class require_login_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $debuginfo Information to aid the debugging process
|
||||
*/
|
||||
function __construct($debuginfo) {
|
||||
parent::__construct('requireloginerror', 'error', '', NULL, $debuginfo);
|
||||
public function __construct($debuginfo) {
|
||||
parent::__construct('requireloginerror', 'error', '', null, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
*
|
||||
* This exception is thrown from require_login()
|
||||
*
|
||||
* @package core_access
|
||||
* @package core
|
||||
* @copyright 2015 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
@ -18,22 +18,24 @@
|
||||
* Exceptions indicating user does not have permissions to do something
|
||||
* and the execution can not continue.
|
||||
*
|
||||
* @package core_access
|
||||
* @package core
|
||||
* @copyright 2009 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class required_capability_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param 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
|
||||
*/
|
||||
function __construct($context, $capability, $errormessage, $stringfile) {
|
||||
public function __construct($context, $capability, $errormessage, $stringfile) {
|
||||
$capabilityname = get_capability_string($capability);
|
||||
if ($context->contextlevel == CONTEXT_MODULE and preg_match('/:view$/', $capability)) {
|
||||
// we can not go to mod/xx/view.php because we most probably do not have cap to view it, let's go to course instead
|
||||
if ($context->contextlevel == CONTEXT_MODULE && preg_match('/:view$/', $capability)) {
|
||||
// Cannot redirect to mod/xx/view.php because we most probably do not have cap to view it.
|
||||
// Redirect to the course instead.
|
||||
$parentcontext = $context->get_parent_context();
|
||||
$link = $parentcontext->get_url();
|
||||
} else {
|
||||
|
@ -21,15 +21,19 @@
|
||||
* @deprecated since Moodle 2.2 - use moodle exception instead
|
||||
* 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
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class webservice_parameter_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $errorcode The name of the string from webservice.php to print
|
||||
* @param string $a The name of the parameter
|
||||
* @param string $debuginfo Optional information to aid debugging
|
||||
*/
|
||||
function __construct($errorcode=null, $a = '', $debuginfo = null) {
|
||||
public function __construct($errorcode = null, $a = '', $debuginfo = null) {
|
||||
parent::__construct($errorcode, 'webservice', '', $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
@ -55,13 +55,15 @@ class bootstrap_renderer {
|
||||
/**
|
||||
* Handles re-entrancy. Without this, errors or debugging output that occur
|
||||
* during the initialisation of $OUTPUT, cause infinite recursion.
|
||||
* @var boolean
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $initialising = false;
|
||||
|
||||
/**
|
||||
* Have we started output yet?
|
||||
* @return boolean true if the header has been printed.
|
||||
* Whether output has started yet.
|
||||
*
|
||||
* @return bool true if the header has been printed.
|
||||
*/
|
||||
public function has_started() {
|
||||
return false;
|
||||
@ -69,42 +71,45 @@ class bootstrap_renderer {
|
||||
|
||||
/**
|
||||
* Constructor - to be used by core code only.
|
||||
*
|
||||
* @param string $method The method to call
|
||||
* @param array $arguments Arguments to pass to the method being called
|
||||
* @return string
|
||||
*/
|
||||
public function __call($method, $arguments) {
|
||||
// phpcs:disable moodle.PHP.ForbiddenGlobalUse.BadGlobal
|
||||
global $OUTPUT, $PAGE;
|
||||
|
||||
$recursing = false;
|
||||
if ($method == 'notification') {
|
||||
// Catch infinite recursion caused by debugging output during print_header.
|
||||
// phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
|
||||
$backtrace = debug_backtrace();
|
||||
array_shift($backtrace);
|
||||
array_shift($backtrace);
|
||||
$recursing = is_early_init($backtrace);
|
||||
}
|
||||
|
||||
$earlymethods = array(
|
||||
$earlymethods = [
|
||||
'fatal_error' => 'early_error',
|
||||
'notification' => 'early_notification',
|
||||
);
|
||||
];
|
||||
|
||||
// If lib/outputlib.php has been loaded, call it.
|
||||
if (!empty($PAGE) && !$recursing) {
|
||||
if (array_key_exists($method, $earlymethods)) {
|
||||
//prevent PAGE->context warnings - exceptions might appear before we set any context
|
||||
// Prevent PAGE->context warnings - exceptions might appear before we set any context.
|
||||
$PAGE->set_context(null);
|
||||
}
|
||||
$PAGE->initialise_theme_and_output();
|
||||
return call_user_func_array(array($OUTPUT, $method), $arguments);
|
||||
return call_user_func_array([$OUTPUT, $method], $arguments);
|
||||
}
|
||||
|
||||
$this->initialising = true;
|
||||
|
||||
// Too soon to initialise $OUTPUT, provide a couple of key methods.
|
||||
if (array_key_exists($method, $earlymethods)) {
|
||||
return call_user_func_array(array('bootstrap_renderer', $earlymethods[$method]), $arguments);
|
||||
return call_user_func_array(['bootstrap_renderer', $earlymethods[$method]], $arguments);
|
||||
}
|
||||
|
||||
throw new coding_exception('Attempt to start output before enough information is known to initialise the theme.');
|
||||
@ -112,7 +117,7 @@ class bootstrap_renderer {
|
||||
|
||||
/**
|
||||
* Returns nicely formatted error message in a div box.
|
||||
* @static
|
||||
*
|
||||
* @param string $message error message
|
||||
* @param ?string $moreinfourl (ignored in early errors)
|
||||
* @param ?string $link (ignored in early errors)
|
||||
@ -137,10 +142,13 @@ class bootstrap_renderer {
|
||||
} else {
|
||||
// Because weblib is not available for these early errors, we
|
||||
// just duplicate s() code here to be safe.
|
||||
$debuginfo = preg_replace('/&#(\d+|x[0-9a-f]+);/i', '&#$1;',
|
||||
htmlspecialchars($debuginfo, ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE));
|
||||
$debuginfo = preg_replace(
|
||||
'/&#(\d+|x[0-9a-f]+);/i',
|
||||
'&#$1;',
|
||||
htmlspecialchars($debuginfo, ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE)
|
||||
);
|
||||
}
|
||||
$debuginfo = str_replace("\n", '<br />', $debuginfo); // keep newlines
|
||||
$debuginfo = str_replace("\n", '<br />', $debuginfo); // Keep newlines.
|
||||
$content .= '<div class="notifytiny">Debug info: ' . $debuginfo . '</div>';
|
||||
}
|
||||
if (!empty($backtrace)) {
|
||||
@ -153,7 +161,7 @@ class bootstrap_renderer {
|
||||
|
||||
/**
|
||||
* This function should only be called by this class, or from exception handlers
|
||||
* @static
|
||||
*
|
||||
* @param string $message error message
|
||||
* @param string $moreinfourl (ignored in early errors)
|
||||
* @param string $link (ignored in early errors)
|
||||
@ -166,7 +174,7 @@ class bootstrap_renderer {
|
||||
|
||||
if (CLI_SCRIPT) {
|
||||
echo "!!! $message !!!\n";
|
||||
if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) {
|
||||
if (!empty($CFG->debug) && $CFG->debug >= DEBUG_DEVELOPER) {
|
||||
if (!empty($debuginfo)) {
|
||||
echo "\nDebug info: $debuginfo";
|
||||
}
|
||||
@ -175,13 +183,12 @@ class bootstrap_renderer {
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
} else if (AJAX_SCRIPT) {
|
||||
$e = new stdClass();
|
||||
$e->error = $message;
|
||||
$e->stacktrace = NULL;
|
||||
$e->debuginfo = NULL;
|
||||
if (!empty($CFG->debug) and $CFG->debug >= DEBUG_DEVELOPER) {
|
||||
$e->stacktrace = null;
|
||||
$e->debuginfo = null;
|
||||
if (!empty($CFG->debug) && $CFG->debug >= DEBUG_DEVELOPER) {
|
||||
if (!empty($debuginfo)) {
|
||||
$e->debuginfo = $debuginfo;
|
||||
}
|
||||
@ -200,7 +207,7 @@ class bootstrap_renderer {
|
||||
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
|
||||
@header($protocol . ' 500 Internal Server Error');
|
||||
|
||||
// better disable any caching
|
||||
// Better disable any caching.
|
||||
@header('Content-Type: text/html; charset=utf-8');
|
||||
@header('X-UA-Compatible: IE=edge');
|
||||
@header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
@ -222,7 +229,7 @@ class bootstrap_renderer {
|
||||
|
||||
/**
|
||||
* Early notification message
|
||||
* @static
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $classes usually notifyproblem or notifysuccess
|
||||
* @return string
|
||||
@ -233,26 +240,27 @@ class bootstrap_renderer {
|
||||
|
||||
/**
|
||||
* Page should redirect message.
|
||||
* @static
|
||||
*
|
||||
* @param string $encodedurl redirect url
|
||||
* @return string
|
||||
*/
|
||||
public static function plain_redirect_message($encodedurl) {
|
||||
$message = '<div style="margin-top: 3em; margin-left:auto; margin-right:auto; text-align:center;">' . get_string('pageshouldredirect') . '<br /><a href="'.
|
||||
$encodedurl .'">'. get_string('continue') .'</a></div>';
|
||||
$message = '<div style="margin-top: 3em; margin-left:auto; margin-right:auto; text-align:center;">';
|
||||
$message .= get_string('pageshouldredirect') . '<br /><a href="';
|
||||
$message .= $encodedurl . '">' . get_string('continue') . '</a></div>';
|
||||
return self::plain_page(get_string('redirect'), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Early redirection page, used before full init of $PAGE global
|
||||
* @static
|
||||
* Early redirection page, used before full init of $PAGE global.
|
||||
*
|
||||
* @param string $encodedurl redirect url
|
||||
* @param string $message redirect message
|
||||
* @param int $delay time in seconds
|
||||
* @return string redirect page
|
||||
*/
|
||||
public static function early_redirect_message($encodedurl, $message, $delay) {
|
||||
$meta = '<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />';
|
||||
$meta = '<meta http-equiv="refresh" content="' . $delay . '; url=' . $encodedurl . '" />';
|
||||
$content = self::early_error_content($message, null, null, null);
|
||||
$content .= self::plain_redirect_message($encodedurl);
|
||||
|
||||
@ -261,7 +269,7 @@ class bootstrap_renderer {
|
||||
|
||||
/**
|
||||
* Output basic html page.
|
||||
* @static
|
||||
*
|
||||
* @param string $title page title
|
||||
* @param string $content page content
|
||||
* @param string $meta meta tag
|
||||
|
Loading…
x
Reference in New Issue
Block a user