mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-12886 refacoring: the external_param is in fact value because we use it also in return structures
This commit is contained in:
parent
2965d271d9
commit
04d212ce4d
3 changed files with 18 additions and 18 deletions
|
@ -74,7 +74,7 @@ class external_api {
|
|||
* @return mixed params with added defaults for optional items, invalid_parameters_exception thrown if any problem found
|
||||
*/
|
||||
public static function validate_parameters(external_description $description, $params) {
|
||||
if ($description instanceof external_param) {
|
||||
if ($description instanceof external_value) {
|
||||
if (is_array($params) or is_object($params)) {
|
||||
throw new invalid_parameter_exception('Scalar type expected, array or object received.');
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ class external_api {
|
|||
if ($subdesc->required) {
|
||||
throw new invalid_parameter_exception('Missing required key in single structure.');
|
||||
}
|
||||
if ($subdesc instanceof external_param) {
|
||||
if ($subdesc instanceof external_value) {
|
||||
$result[$key] = self::validate_parameters($subdesc, $subdesc->default);
|
||||
}
|
||||
} else {
|
||||
|
@ -181,10 +181,10 @@ abstract class external_description {
|
|||
}
|
||||
|
||||
/**
|
||||
* Scalar parameter description class
|
||||
* Scalar alue description class
|
||||
*/
|
||||
class external_param extends external_description {
|
||||
/** @property mixed $type parameter type PARAM_XX */
|
||||
class external_value extends external_description {
|
||||
/** @property mixed $type value type PARAM_XX */
|
||||
public $type;
|
||||
/** @property mixed $default default value */
|
||||
public $default;
|
||||
|
|
|
@ -32,8 +32,8 @@ require_once($CFG->libdir . '/externallib.php');
|
|||
class externallib_test extends UnitTestCase {
|
||||
public function test_validate_params() {
|
||||
$params = array('text'=>'aaa', 'someid'=>'6',);
|
||||
$description = new external_function_parameters(array('someid' => new external_param(PARAM_INT, 'Some int value'),
|
||||
'text' => new external_param(PARAM_ALPHA, 'Some text value')));
|
||||
$description = new external_function_parameters(array('someid' => new external_value(PARAM_INT, 'Some int value'),
|
||||
'text' => new external_value(PARAM_ALPHA, 'Some text value')));
|
||||
$result = external_api::validate_parameters($description, $params);
|
||||
$this->assertEqual(count($result), 2);
|
||||
reset($result);
|
||||
|
@ -43,8 +43,8 @@ class externallib_test extends UnitTestCase {
|
|||
|
||||
|
||||
$params = array('someids'=>array('1', 2, 'a'=>'3'), 'scalar'=>666);
|
||||
$description = new external_function_parameters(array('someids' => new external_multiple_structure(new external_param(PARAM_INT, 'Some ID')),
|
||||
'scalar' => new external_param(PARAM_ALPHANUM, 'Some text value')));
|
||||
$description = new external_function_parameters(array('someids' => new external_multiple_structure(new external_value(PARAM_INT, 'Some ID')),
|
||||
'scalar' => new external_value(PARAM_ALPHANUM, 'Some text value')));
|
||||
$result = external_api::validate_parameters($description, $params);
|
||||
$this->assertEqual(count($result), 2);
|
||||
reset($result);
|
||||
|
@ -54,8 +54,8 @@ class externallib_test extends UnitTestCase {
|
|||
|
||||
|
||||
$params = array('text'=>'aaa');
|
||||
$description = new external_function_parameters(array('someid' => new external_param(PARAM_INT, 'Some int value', false),
|
||||
'text' => new external_param(PARAM_ALPHA, 'Some text value')));
|
||||
$description = new external_function_parameters(array('someid' => new external_value(PARAM_INT, 'Some int value', false),
|
||||
'text' => new external_value(PARAM_ALPHA, 'Some text value')));
|
||||
$result = external_api::validate_parameters($description, $params);
|
||||
$this->assertEqual(count($result), 2);
|
||||
reset($result);
|
||||
|
@ -65,8 +65,8 @@ class externallib_test extends UnitTestCase {
|
|||
|
||||
|
||||
$params = array('text'=>'aaa');
|
||||
$description = new external_function_parameters(array('someid' => new external_param(PARAM_INT, 'Some int value', false, 6),
|
||||
'text' => new external_param(PARAM_ALPHA, 'Some text value')));
|
||||
$description = new external_function_parameters(array('someid' => new external_value(PARAM_INT, 'Some int value', false, 6),
|
||||
'text' => new external_value(PARAM_ALPHA, 'Some text value')));
|
||||
$result = external_api::validate_parameters($description, $params);
|
||||
$this->assertEqual(count($result), 2);
|
||||
reset($result);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue