Skip to content

Commit 8c3f18a

Browse files
committed
MDL-81919 core: Move classes out of lib/setuplib.php
1 parent 302b94c commit 8c3f18a

15 files changed

+804
-569
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Exception indicating programming error, must be fixed by a programer. For example
19+
* a core API might throw this type of exception if a plugin calls it incorrectly.
20+
*
21+
* @package core
22+
* @subpackage lib
23+
* @copyright 2008 Petr Skoda {@link http://skodak.org}
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
*/
26+
class coding_exception extends moodle_exception {
27+
/**
28+
* Constructor
29+
* @param string $hint short description of problem
30+
* @param string $debuginfo detailed information how to fix problem
31+
*/
32+
function __construct($hint, $debuginfo=null) {
33+
parent::__construct('codingerror', 'debug', '', $hint, $debuginfo);
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
18+
/**
19+
* An exception that indicates that file can not be served
20+
*
21+
* @package core
22+
* @subpackage lib
23+
* @copyright 2010 Petr Skoda {@link http://skodak.org}
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
*/
26+
class file_serving_exception extends moodle_exception {
27+
/**
28+
* Constructor
29+
* @param string $debuginfo optional more detailed information
30+
*/
31+
function __construct($debuginfo = NULL) {
32+
parent::__construct('cannotservefile', 'error', '', NULL, $debuginfo);
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
18+
/**
19+
* An exception that indicates incorrect permissions in $CFG->dataroot
20+
*
21+
* @package core
22+
* @subpackage lib
23+
* @copyright 2010 Petr Skoda {@link http://skodak.org}
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
*/
26+
class invalid_dataroot_permissions extends moodle_exception {
27+
/**
28+
* Constructor
29+
* @param string $debuginfo optional more detailed information
30+
*/
31+
function __construct($debuginfo = NULL) {
32+
parent::__construct('invaliddatarootpermissions', 'error', '', NULL, $debuginfo);
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Exception indicating malformed parameter problem.
19+
* This exception is not supposed to be thrown when processing
20+
* user submitted data in forms. It is more suitable
21+
* for WS and other low level stuff.
22+
*
23+
* @package core
24+
* @subpackage lib
25+
* @copyright 2009 Petr Skoda {@link http://skodak.org}
26+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27+
*/
28+
class invalid_parameter_exception extends moodle_exception {
29+
/**
30+
* Constructor
31+
* @param string $debuginfo some detailed information
32+
*/
33+
function __construct($debuginfo=null) {
34+
parent::__construct('invalidparameter', 'debug', '', null, $debuginfo);
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Exception indicating malformed response problem.
19+
* This exception is not supposed to be thrown when processing
20+
* user submitted data in forms. It is more suitable
21+
* for WS and other low level stuff.
22+
*/
23+
class invalid_response_exception extends moodle_exception {
24+
/**
25+
* Constructor
26+
* @param string $debuginfo some detailed information
27+
*/
28+
function __construct($debuginfo=null) {
29+
parent::__construct('invalidresponse', 'debug', '', null, $debuginfo);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* An exception that indicates something really weird happened. For example,
19+
* if you do switch ($context->contextlevel), and have one case for each
20+
* CONTEXT_... constant. You might throw an invalid_state_exception in the
21+
* default case, to just in case something really weird is going on, and
22+
* $context->contextlevel is invalid - rather than ignoring this possibility.
23+
*
24+
* @package core
25+
* @subpackage lib
26+
* @copyright 2009 onwards Martin Dougiamas {@link http://moodle.com}
27+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28+
*/
29+
class invalid_state_exception extends moodle_exception {
30+
/**
31+
* Constructor
32+
* @param string $hint short description of problem
33+
* @param string $debuginfo optional more detailed information
34+
*/
35+
function __construct($hint, $debuginfo=null) {
36+
parent::__construct('invalidstatedetected', 'debug', '', $hint, $debuginfo);
37+
}
38+
}
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Base Moodle Exception class
19+
*
20+
* Although this class is defined here, you cannot throw a moodle_exception until
21+
* after moodlelib.php has been included (which will happen very soon).
22+
*
23+
* @package core
24+
* @subpackage lib
25+
* @copyright 2008 Petr Skoda {@link http://skodak.org}
26+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27+
*/
28+
class moodle_exception extends \Exception {
29+
30+
/**
31+
* @var string The name of the string from error.php to print
32+
*/
33+
public $errorcode;
34+
35+
/**
36+
* @var string The name of module
37+
*/
38+
public $module;
39+
40+
/**
41+
* @var mixed Extra words and phrases that might be required in the error string
42+
*/
43+
public $a;
44+
45+
/**
46+
* @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.
47+
*/
48+
public $link;
49+
50+
/**
51+
* @var string Optional information to aid the debugging process
52+
*/
53+
public $debuginfo;
54+
55+
/**
56+
* Constructor
57+
* @param string $errorcode The name of the string from error.php to print
58+
* @param string $module name of module
59+
* @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.
60+
* @param mixed $a Extra words and phrases that might be required in the error string
61+
* @param string $debuginfo optional debugging information
62+
*/
63+
function __construct($errorcode, $module='', $link='', $a=NULL, $debuginfo=null) {
64+
global $CFG;
65+
66+
if (empty($module) || $module == 'moodle' || $module == 'core') {
67+
$module = 'error';
68+
}
69+
70+
$this->errorcode = $errorcode;
71+
$this->module = $module;
72+
$this->link = $link;
73+
$this->a = $a;
74+
$this->debuginfo = is_null($debuginfo) ? null : (string)$debuginfo;
75+
76+
if (get_string_manager()->string_exists($errorcode, $module)) {
77+
$message = get_string($errorcode, $module, $a);
78+
$haserrorstring = true;
79+
} else {
80+
$message = $module . '/' . $errorcode;
81+
$haserrorstring = false;
82+
}
83+
84+
$isinphpunittest = (defined('PHPUNIT_TEST') && PHPUNIT_TEST);
85+
$hasdebugdeveloper = (
86+
isset($CFG->debugdisplay) &&
87+
isset($CFG->debug) &&
88+
$CFG->debugdisplay &&
89+
$CFG->debug === DEBUG_DEVELOPER
90+
);
91+
92+
if ($debuginfo) {
93+
if ($isinphpunittest || $hasdebugdeveloper) {
94+
$message = "$message ($debuginfo)";
95+
}
96+
}
97+
98+
if (!$haserrorstring and $isinphpunittest) {
99+
// Append the contents of $a to $debuginfo so helpful information isn't lost.
100+
// This emulates what {@link get_exception_info()} does. Unfortunately that
101+
// function is not used by phpunit.
102+
$message .= PHP_EOL.'$a contents: '.print_r($a, true);
103+
}
104+
105+
parent::__construct($message, 0);
106+
}
107+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Course/activity access exception.
19+
*
20+
* This exception is thrown from require_login()
21+
*
22+
* @package core_access
23+
* @copyright 2010 Petr Skoda {@link http://skodak.org}
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
*/
26+
class require_login_exception extends moodle_exception {
27+
/**
28+
* Constructor
29+
* @param string $debuginfo Information to aid the debugging process
30+
*/
31+
function __construct($debuginfo) {
32+
parent::__construct('requireloginerror', 'error', '', NULL, $debuginfo);
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Session timeout exception.
19+
*
20+
* This exception is thrown from require_login()
21+
*
22+
* @package core_access
23+
* @copyright 2015 Andrew Nicols <[email protected]>
24+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25+
*/
26+
class require_login_session_timeout_exception extends require_login_exception {
27+
/**
28+
* Constructor
29+
*/
30+
public function __construct() {
31+
moodle_exception::__construct('sessionerroruser', 'error');
32+
}
33+
}

0 commit comments

Comments
 (0)