Skip to content

Commit

Permalink
MDL-12886 refacoring: the external_param is in fact value because we …
Browse files Browse the repository at this point in the history
…use it also in return structures
  • Loading branch information
skodak committed Oct 7, 2009
1 parent 2965d27 commit 04d212c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions group/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function create_groups_returns() {
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'))
)
);
}
Expand Down Expand Up @@ -119,10 +119,10 @@ public static function get_groups_returns() {
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')
)
)
);
Expand Down
10 changes: 5 additions & 5 deletions lib/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function set_timeout($seconds=360) {
* @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.');
}
Expand All @@ -90,7 +90,7 @@ public static function validate_parameters(external_description $description, $p
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 {
Expand Down Expand Up @@ -181,10 +181,10 @@ public function __construct($desc, $required) {
}

/**
* 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;
Expand Down
16 changes: 8 additions & 8 deletions lib/simpletest/testexternallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
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);
Expand All @@ -43,8 +43,8 @@ public function test_validate_params() {


$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);
Expand All @@ -54,8 +54,8 @@ public function test_validate_params() {


$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);
Expand All @@ -65,8 +65,8 @@ public function test_validate_params() {


$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);
Expand Down

0 comments on commit 04d212c

Please sign in to comment.