MDL-12886 refacoring: the external_param is in fact value because we use it also in return structures

This commit is contained in:
skodak 2009-10-07 21:49:03 +00:00
parent 2965d271d9
commit 04d212ce4d
3 changed files with 18 additions and 18 deletions

View File

@ -82,7 +82,7 @@ class moodle_group_external extends external_api {
public static function get_groups_parameters() {
return new external_function_parameters(
array(
'groupids' => new external_multiple_structure(new external_param(PARAM_INT, 'Group ID'))
'groupids' => new external_multiple_structure(new external_value(PARAM_INT, 'Group ID'))
)
);
}
@ -119,10 +119,10 @@ class moodle_group_external extends external_api {
return new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_param(PARAM_INT, 'some group id'),
'name' => new external_param(PARAM_TEXT, 'multilang compatible name, course unique'),
'description' => new external_param(PARAM_RAW, 'just some text'),
'enrolmentkey' => new external_param(PARAM_RAW, 'group enrol secret phrase')
'id' => new external_value(PARAM_INT, 'some group id'),
'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),
'description' => new external_value(PARAM_RAW, 'just some text'),
'enrolmentkey' => new external_value(PARAM_RAW, 'group enrol secret phrase')
)
)
);

View File

@ -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;

View File

@ -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);