1 |
efrain |
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 |
namespace core_external;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Common ancestor of all parameter description classes
|
|
|
21 |
*
|
|
|
22 |
* @package core_external
|
|
|
23 |
* @copyright 2009 Petr Skodak
|
|
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
25 |
*/
|
|
|
26 |
abstract class external_description {
|
|
|
27 |
/** @var string Description of element */
|
|
|
28 |
public $desc;
|
|
|
29 |
|
|
|
30 |
/** @var bool Element value required, null not allowed */
|
|
|
31 |
public $required;
|
|
|
32 |
|
|
|
33 |
/** @var mixed Default value */
|
|
|
34 |
public $default;
|
|
|
35 |
|
|
|
36 |
/** @var bool Allow null values */
|
|
|
37 |
public $allownull;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Contructor.
|
|
|
41 |
*
|
|
|
42 |
* @param string $desc Description of element
|
|
|
43 |
* @param int $required Whether the element value is required. Valid values are VALUE_DEFAULT, VALUE_REQUIRED, VALUE_OPTIONAL.
|
|
|
44 |
* @param mixed $default The default value
|
|
|
45 |
* @param bool $allownull Allow null value
|
|
|
46 |
*/
|
|
|
47 |
public function __construct($desc, $required, $default, $allownull = NULL_NOT_ALLOWED) {
|
|
|
48 |
if (!in_array($required, [VALUE_DEFAULT, VALUE_REQUIRED, VALUE_OPTIONAL], true)) {
|
|
|
49 |
$requiredstr = $required;
|
|
|
50 |
if (is_array($required)) {
|
|
|
51 |
$requiredstr = "Array: " . implode(" ", $required);
|
|
|
52 |
}
|
|
|
53 |
debugging("Invalid \$required parameter value: '{$requiredstr}' .
|
|
|
54 |
It must be either VALUE_DEFAULT, VALUE_REQUIRED, or VALUE_OPTIONAL", DEBUG_DEVELOPER);
|
|
|
55 |
}
|
|
|
56 |
$this->desc = $desc;
|
|
|
57 |
$this->required = $required;
|
|
|
58 |
$this->default = $default;
|
|
|
59 |
$this->allownull = (bool)$allownull;
|
|
|
60 |
}
|
|
|
61 |
}
|