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() { public static function get_groups_parameters() {
return new external_function_parameters( return new external_function_parameters(
array( 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( return new external_multiple_structure(
new external_single_structure( new external_single_structure(
array( array(
'id' => new external_param(PARAM_INT, 'some group id'), 'id' => new external_value(PARAM_INT, 'some group id'),
'name' => new external_param(PARAM_TEXT, 'multilang compatible name, course unique'), 'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),
'description' => new external_param(PARAM_RAW, 'just some text'), 'description' => new external_value(PARAM_RAW, 'just some text'),
'enrolmentkey' => new external_param(PARAM_RAW, 'group enrol secret phrase') '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 * @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) { 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)) { if (is_array($params) or is_object($params)) {
throw new invalid_parameter_exception('Scalar type expected, array or object received.'); throw new invalid_parameter_exception('Scalar type expected, array or object received.');
} }
@ -90,7 +90,7 @@ class external_api {
if ($subdesc->required) { if ($subdesc->required) {
throw new invalid_parameter_exception('Missing required key in single structure.'); 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); $result[$key] = self::validate_parameters($subdesc, $subdesc->default);
} }
} else { } else {
@ -181,10 +181,10 @@ abstract class external_description {
} }
/** /**
* Scalar parameter description class * Scalar alue description class
*/ */
class external_param extends external_description { class external_value extends external_description {
/** @property mixed $type parameter type PARAM_XX */ /** @property mixed $type value type PARAM_XX */
public $type; public $type;
/** @property mixed $default default value */ /** @property mixed $default default value */
public $default; public $default;

View File

@ -32,8 +32,8 @@ require_once($CFG->libdir . '/externallib.php');
class externallib_test extends UnitTestCase { class externallib_test extends UnitTestCase {
public function test_validate_params() { public function test_validate_params() {
$params = array('text'=>'aaa', 'someid'=>'6',); $params = array('text'=>'aaa', 'someid'=>'6',);
$description = new external_function_parameters(array('someid' => new external_param(PARAM_INT, 'Some int value'), $description = new external_function_parameters(array('someid' => new external_value(PARAM_INT, 'Some int value'),
'text' => new external_param(PARAM_ALPHA, 'Some text value'))); 'text' => new external_value(PARAM_ALPHA, 'Some text value')));
$result = external_api::validate_parameters($description, $params); $result = external_api::validate_parameters($description, $params);
$this->assertEqual(count($result), 2); $this->assertEqual(count($result), 2);
reset($result); reset($result);
@ -43,8 +43,8 @@ class externallib_test extends UnitTestCase {
$params = array('someids'=>array('1', 2, 'a'=>'3'), 'scalar'=>666); $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')), $description = new external_function_parameters(array('someids' => new external_multiple_structure(new external_value(PARAM_INT, 'Some ID')),
'scalar' => new external_param(PARAM_ALPHANUM, 'Some text value'))); 'scalar' => new external_value(PARAM_ALPHANUM, 'Some text value')));
$result = external_api::validate_parameters($description, $params); $result = external_api::validate_parameters($description, $params);
$this->assertEqual(count($result), 2); $this->assertEqual(count($result), 2);
reset($result); reset($result);
@ -54,8 +54,8 @@ class externallib_test extends UnitTestCase {
$params = array('text'=>'aaa'); $params = array('text'=>'aaa');
$description = new external_function_parameters(array('someid' => new external_param(PARAM_INT, 'Some int value', false), $description = new external_function_parameters(array('someid' => new external_value(PARAM_INT, 'Some int value', false),
'text' => new external_param(PARAM_ALPHA, 'Some text value'))); 'text' => new external_value(PARAM_ALPHA, 'Some text value')));
$result = external_api::validate_parameters($description, $params); $result = external_api::validate_parameters($description, $params);
$this->assertEqual(count($result), 2); $this->assertEqual(count($result), 2);
reset($result); reset($result);
@ -65,8 +65,8 @@ class externallib_test extends UnitTestCase {
$params = array('text'=>'aaa'); $params = array('text'=>'aaa');
$description = new external_function_parameters(array('someid' => new external_param(PARAM_INT, 'Some int value', false, 6), $description = new external_function_parameters(array('someid' => new external_value(PARAM_INT, 'Some int value', false, 6),
'text' => new external_param(PARAM_ALPHA, 'Some text value'))); 'text' => new external_value(PARAM_ALPHA, 'Some text value')));
$result = external_api::validate_parameters($description, $params); $result = external_api::validate_parameters($description, $params);
$this->assertEqual(count($result), 2); $this->assertEqual(count($result), 2);
reset($result); reset($result);