本文整理汇总了PHP中external_api::validate_parameters方法的典型用法代码示例。如果您正苦于以下问题:PHP external_api::validate_parameters方法的具体用法?PHP external_api::validate_parameters怎么用?PHP external_api::validate_parameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类external_api
的用法示例。
在下文中一共展示了external_api::validate_parameters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_validate_params
public function test_validate_params()
{
$params = array('text' => 'aaa', 'someid' => '6');
$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->assertCount(2, $result);
reset($result);
$this->assertSame('someid', key($result));
$this->assertSame(6, $result['someid']);
$this->assertSame('aaa', $result['text']);
$params = array('someids' => array('1', 2, 'a' => '3'), 'scalar' => 666);
$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->assertCount(2, $result);
reset($result);
$this->assertSame('someids', key($result));
$this->assertEquals(array(0 => 1, 1 => 2, 2 => 3), $result['someids']);
$this->assertSame('666', $result['scalar']);
$params = array('text' => 'aaa');
$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->assertCount(2, $result);
reset($result);
$this->assertSame('someid', key($result));
$this->assertNull($result['someid']);
$this->assertSame('aaa', $result['text']);
$params = array('text' => 'aaa');
$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->assertCount(2, $result);
reset($result);
$this->assertSame('someid', key($result));
$this->assertSame(6, $result['someid']);
$this->assertSame('aaa', $result['text']);
}
示例2: urlencode
$testclient = new $testclientclass();
$serverurl = "{$CFG->wwwroot}/webservice/{$protocol}/";
if ($authmethod == 'simple') {
$serverurl .= 'simpleserver.php';
$serverurl .= '?wsusername=' . urlencode($data->wsusername);
$serverurl .= '&wspassword=' . urlencode($data->wspassword);
} else {
if ($authmethod == 'token') {
$serverurl .= 'server.php';
$serverurl .= '?wstoken=' . urlencode($data->token);
}
}
// now get the function parameters
$params = $mform->get_params();
// now test the parameters, this also fixes PHP data types
$params = external_api::validate_parameters($functioninfo->parameters_desc, $params);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('pluginname', 'webservice_' . $protocol) . ': ' . $function);
echo 'URL: ' . s($serverurl);
echo $OUTPUT->box_start();
try {
$response = $testclient->simpletest($serverurl, $function, $params);
echo str_replace("\n", '<br />', s(var_export($response, true)));
} catch (Exception $ex) {
//TODO: handle exceptions and faults without exposing of the sensitive information such as debug traces!
echo str_replace("\n", '<br />', s($ex));
}
echo $OUTPUT->box_end();
$mform->display();
echo $OUTPUT->footer();
die;