当前位置: 首页>>代码示例>>PHP>>正文


PHP external_api::validate_parameters方法代码示例

本文整理汇总了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']);
 }
开发者ID:jackdaniels79,项目名称:moodle,代码行数:35,代码来源:externallib_test.php

示例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;
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:testclient.php


注:本文中的external_api::validate_parameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。